- 浏览: 188270 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (228)
- 链接数据库 (1)
- Linux下面安装tomcat步骤 (1)
- 数据库简单添加索引 (1)
- Ubuntu 16.04安装jdk步骤 (1)
- Ubuntu 16.04安装mysql链接工具workbench (1)
- Java基础 (1)
- Java 获取两个时间的时间查 如 1 天 2 小时 30 分钟 (1)
- jdbc链接增删该查 (1)
- springboot 跨域解决 (1)
- springboot如何读取配置文件(application.yml)中的属性值 (1)
- springboot配置redis (1)
- 数据库访问优化法则 (1)
- springboot 配置定时任务 (1)
- 使用Spring Boot上传文件 (1)
- Java并发编程:Callable、Future和FutureTask (1)
- springboot配置所有信息demo (1)
- 常用软件地址 (1)
- Java DateUtil时间大全 (1)
- Java DateUtil当天,本周,本月时间获取方法 (1)
- @Data的用法 (1)
- 身份证工具类 (1)
- springboot添加日志 (1)
- List集合中的对象按照某个字段去重实现 (1)
- JavaBean和Map转换封装类 (1)
- StringUtils工具类用法 (1)
- BigDecimal用户详情 (1)
- java常用集合总结 (1)
- openfile 插件开发步骤 (0)
- Linux rpc客户端步骤 (1)
- Java开发必会的Linux命令 (1)
- springboot配置拦截器,控制登录跳转 (1)
- springboot 异步调用的方法 (0)
- springboot如何读取配置文件test.properties (1)
- springboot 异步调用的方法 (1)
- HttpClient操作,HttpPost (1)
- HttpGet (1)
- HttpDelete (1)
- HttpPut (1)
- mybatis生成代码后,想用自己的关联查询demo (1)
- Arrays工具类十大常用方法 (1)
- 如何生成唯一订单号 (1)
- 订单号唯一性 (1)
- msyql lest的用法 (1)
- //循环递归删除 (0)
- 循环递归删除 (1)
- java 属性首字母大写返回json解决办法 (1)
- 根据两点间经纬度坐标(double值),计算两点间距离,单位为米 (1)
- 运用开发好的jar部署到linux服务中 (1)
- mybatis批量新增 (1)
- mybatis 增删该查demo,新手必看 (1)
- java中字符串查找一个字符串的个数几种方法 (1)
- @Select in 的用法 (1)
- Ubuntu 16.04使用ieda简单配置 (1)
- 统计一个字符串中相应字符出现的次数 (1)
- SimpleDateFormat同步的解决办法 (1)
- gradle打包springboot jar例子 (1)
- java 提取字符串中的数字 (1)
- springboot 对像异常处理,还可以作为全部异常处理 (1)
- 面试题 (0)
- Linux下面安装virtualBox (1)
- java带有效期的map (1)
- 2018年JAVA基础面试题和高级面试题总结 (1)
- mysql修改密码的方法 (1)
- 排名前 16 的 Java 工具类 (1)
- 最完整的Linux常用命令大全 (1)
- Mysql 开发标准规范 (1)
- idea 快捷键 (1)
- mysql 建立索引 (1)
- Java中判断字符串是否为数字的五种方法 (1)
- springboot集成redis (1)
- springboot异步调用demo (1)
- springboot2集成redis (1)
- springboot2集成Elasticsearch (1)
- java过滤敏感字体的方式 (1)
- 对象的值赋给另一个对象 (1)
- mybitse+pagehelper 的使用方法 (1)
- java时间的处理 (1)
- xshell5 下载地址 (1)
- springboot2集成Excel (1)
- 检查数组是否包含某个值的方法 (1)
- 关于Java代码优化的N条建议! (1)
- Java Map按Key值进行排序 (1)
- List进行排序 (1)
- Stream 完整实例 (1)
- StringUtils isNoneBlank和isAnyBlank——demo (1)
- vim最全常用命令 (1)
- JWT生成Token (1)
- 学习参看地址 (1)
- java初始化数据 (1)
- 简单json (1)
- 数据库脚本 (1)
- restTemplate http请求 (1)
- 学习网站 (1)
- JsonUtil (1)
- Rsa (1)
- BeanUtils的赋值方法比较 (1)
- HttpClientUtil (2)
- ValidUtils (0)
- 读取excel,批量插入库demo (1)
- springboot对redis封装使用 (1)
- java后端简答验证码 (1)
- java高级面试题及其答案 (1)
- 序列换成json时 (1)
- 将所有的long变成string (1)
- ControllerAdvice (0)
- RedisService 工具类 (1)
- Java常用正则表达式验证工具类RegexUtils (1)
- CollectionUtil (1)
- thrift使用 (1)
- springboot播客学习 (1)
- mybitse 批量更新 (1)
- https://www.cnblogs.com/cxiaocai/p/11715874.html (1)
- elasticsearch安装及其head步骤 (0)
- elasticsearch7.6.2安装及其head、kibana、ik分词器步骤 (0)
- elasticsearch7.6.2集成springboot (0)
- gradle仓库选址 (1)
- elasticsearch7.6.2集成springboot2.2.6---2 (1)
- elasticsearch7.6.2安装及其head、kibana、ik分词器步骤-----1 (1)
- elasticsearch7.6.2集成springboot2.2.6基本语法---3 (1)
- Jsoup (1)
- elasticsearch7.6.2集成springboot2.2.6----demo (1)
- mybatis官网地址 (1)
- springboot发送邮件到qq (1)
- navicat Premium 链接sql Server的方法 (1)
- 简单开发springboot搭建 (1)
- sqlServer 查询两个小时的sql语句 (1)
- BigDecimalUtil (1)
- 雪花算法生成id (1)
- JsonUtils (1)
- Spring Boot监控与管理的实现 (1)
- springboot 使用undertow启动,替换tomcat (1)
- RedisConfig配置使用 (1)
- RedisUtil (1)
- easypoi读取excel (1)
- easyexcel读取excel (0)
- easyexcel读取excel与下载 (1)
- 生成指定长度的随机数 (1)
- Spring Boot AOP实战 (1)
- fastjsonfastjson新手必看 (1)
- 获取IP地址 (1)
- CommonUtils (1)
- 5万字长文:Stream和Lambda表达式最佳实践-附PDF下载 (1)
- DateUtils 最新工具类 (1)
- screw的使用 (1)
- 15000 字的 SQL 语句大全 (1)
- hutool (1)
- PdfToWord (1)
- MySQL修改最大连接数 (1)
- MAP排序 (1)
- 归纳从文件中读取数据的六种方法-JAVA IO基础总结 (1)
- 天气 (1)
- Intellij IDEA中Mybatis Mapper自动注入警告的6种解决方案 (1)
- 全网最全编程学习网站汇总来了,还不赶快收藏 (1)
- win10 (0)
- 电脑知识 (0)
- util工具类 (1)
- ieda提示mapper报错 (1)
- zysnba (1)
- 自增方式 (1)
- mybits链表查询 (1)
- SpringBoot如何优雅的处理校验参数 (1)
- 参考记录 (1)
- 企业微信封装方法 (1)
- 二维码 (1)
- mysql简单创建索引 (1)
- msyql函数 (1)
- mybitse-plus多表查询demo (1)
- git 提交本地代码步骤 (1)
- gradle5.X以上lombok引入 (1)
- SpringBoot定时任务及Cron表达式详解 (1)
- Hutool工具集之DateUtil(日期时间工具)详解使用 (1)
- 对象属性为空字符串变成null (1)
- DateUtils 工具类 (0)
- face++照片不对工具类 (1)
- 判断某个值是否在list集合中的某个对象中存在 (1)
- mybatisplus时间更新操作 (1)
- Java8 List通用方法处理总结 (1)
- 阿斯蒂芬 (0)
- springboot多数据源配置 (0)
- MyBatis和MyBatis-Plus 官网地址 (1)
- jwt (0)
- java---ValidUtils (1)
- Java之下载网络图片到本地文件夹 (1)
- 初始化内容数据 (1)
- springboot启动指定端口和启动环境 (1)
- 根据生日计算年龄 (1)
- idea快捷键大全 (1)
- springboot数据验证例子 (1)
- springboot文章 (1)
- 获取当前时间,推迟一年 (0)
- 获取当前时间,推迟一周 推迟一年示例 (1)
- ResultBean返回对象 (1)
- SpringBoot注解最全详解 (1)
- JeecgBoot (1)
- 电脑优化 (0)
- 简单数据队列 (1)
- CacheUtil换成工具类 (0)
- CacheUtil缓存工具类 (0)
- xml和对象互转 (0)
- 导出word (0)
- 企业微信通过code获取用户基本信息 (1)
- Java开发中的一些小技巧 (1)
- 判断当前时间是否在一个时间区间例如8点:21点 (1)
- springboot 启动指定环境 (1)
- 打印springboot启动的环境 (1)
- 根据时间日期获取当天是周几 (1)
- LocalDateTimeToString (1)
- java导出word (1)
- java 对xml和对象互转 (1)
- java CacheUtil缓存工具类 (1)
- 史上最牛逼电脑优化,让电脑飞起来 (1)
- isEmpty 和 isBlank 的用法区别 (1)
- 根据图片url地址获取其流InputStream (1)
- springboot解决LocalDateTime (1)
- springboot配置文件list映射 (1)
- SpringBoot中必须掌握的45个注解 (1)
- sql 优化的 15 个小技巧 (1)
- Cron表达式 (1)
- 数据库创建时间和修改时间默认值 (1)
- 小程序解析手机号 (1)
- 小程序获取手机号 (0)
- java 获取resource下面的文件路径,springboot打成jar也可以使用 (1)
- 数据库字段不显示对象和swwager前段不显示 (1)
- java生成pdf (1)
- springboot 异步调用 (1)
- java获取时间段内的每一天 (1)
- hutool----DateUtil简单的时间 (1)
- java 8两个List集合取交集、并集、差集、去重并集 (1)
- 服务调用demo (1)
- hutool导入excel (1)
- hutool导出 (1)
- 切面日志 (1)
- 校验参数为空 (1)
- 两个集合对象某一个属性相匹配 (1)
- JAVA stream流详细教程 (1)
- 查看java进程的命令 (1)
- Java 保留两位小数 百分数 (1)
- freemarker读写word模板生成word文档 (1)
- springboot项目中,读取 resources 目录下的文件的9种方式 (1)
- Knife4j (1)
- Java8 获取两个List交集 (1)
- list泛型和list对象交集 (1)
- 未来7天过生日的孩子sql (1)
- 数据校验,全局异常 (1)
- 获取最近10天过生日的sql (1)
- 随机数 (1)
- Java获取两个日期的天数打印 (1)
- 通过时间获取星期几 (1)
- Java时间类型相互转化 (2)
- 小程序登录 (1)
- 手机号 (0)
- sse调用 (0)
- httpsse调用 (1)
- 初始延迟3秒执行任务 (0)
最新评论
package com.taotao.common.utils;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClientUtil {
public static String doGet(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url, null);
}
public static String doPost(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
public static String doPost(String url) {
return doPost(url, null);
}
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
}
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class HttpClientUtil {
public static String doGet(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url, null);
}
public static String doPost(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList);
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
public static String doPost(String url) {
return doPost(url, null);
}
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return resultString;
}
}
相关推荐
- **实例化HttpClientUtil**:在代码中创建HttpClientUtil的实例。 - **调用方法**:根据需求,调用GET或POST方法,传入必要的参数(如URL、请求头、请求体等)。 - **处理返回值**:获取到的返回值通常是一个...
下面我们将详细讨论HttpClientUtil工具类如何实现这些功能。 首先,HttpClientUtil工具类通常会封装HttpClient的基本操作,以便于开发者在应用中便捷地调用。GET和POST请求是HTTP协议中最常见的两种请求方法。GET...
httpClientUtil工具类
1. **HttpClientUtil 类结构**: 类中定义了一个静态的日志器 LOGGER,用于记录执行过程中的信息,使用的是 SLF4J 日志框架。此外,创建了一个静态的 `CloseableHttpClient` 实例 `client`,这是 HttpClient 的核心...
HttpClientUtil请求第三方接口,可以直接使用,post请求方式、get请求方式都有,直接粘贴复制就ok
该工具类是java 调用第三方接口时需要使用到的。HttpClientUtil 包含get和post方法。
在"HttpClientUtil2-发送json返回json测试通过.java"这个文件中,我们可以预见到这是一个实现了发送JSON数据并接收JSON响应的示例。以下是一些关键知识点: 1. **Apache HttpClient 库**:HttpClient 是 Apache ...
HttpClientUtil4.java 工具类
1.基于HttpClient-4.4.1封装的一个工具类; 2.基于HttpAsycClient-4.1封装的异步HttpClient工具类; 3.javanet包下面是基于jdk自带的UrlConnection进行封装的。 前2个工具类支持插件式配置Header、插件式配置...
自己做项目中用到的,以后保存下来以防以后用到。多多积累。
HttpClient汇总工具类 HttpClient汇总工具类HttpClient汇总工具类HttpClient汇总工具类
多年积累,功能比较强大,可设置路由连接数,时间,请求类型包括get,post, 参数包括urlcode,map,json,xml。注释很清楚。
基于jmeter+Java+HttpclientUtil实现的接口测试工具,通过Excel表格进行维护接口相关参数信息,借助Jmeter工具通过java请求设计接口测试自动化测试用例。代码重写了JavaSampleClient类,在使用过程中取出了冗余的...