Code Monkey home page Code Monkey logo

httpclientutil's Introduction

httpclientutil (QQ群548452686 image

该项目基于HttpClient-4.4.1封装的一个工具类,支持插件式配置Header、插件式配置httpclient对象,这样就可以方便地自定义header信息、配置ssl、配置proxy等。

Maven坐标:

<!-- https://mvnrepository.com/artifact/com.arronlong/httpclientutil -->
<dependency>
    <groupId>com.arronlong</groupId>
    <artifactId>httpclientutil</artifactId>
    <version>1.0.4</version>
</dependency>

简单Demo

在test包里还有各种测试demo,各测试类的源码在src/test/java/com/httpclient/test包路径下。

public static void main(String[] args) throws HttpProcessException, FileNotFoundException {
	String url = "https://github.com/Arronlong/httpclientutil";
	
	//最简单的使用:
	String html = HttpClientUtil.get(HttpConfig.custom().url(url));
	System.out.println(html);
	
	//---------------------------------
	//			【详细说明】
	//--------------------------------
	
	//插件式配置Header(各种header信息、自定义header)
	Header[] headers = HttpHeader.custom()
						 		 .userAgent("javacl")
								 .other("customer", "自定义")
								 .build();
	
	//插件式配置生成HttpClient时所需参数(超时、连接池、ssl、重试)
	HCB hcb = HCB.custom()
				 .timeout(1000) //超时
				 .pool(100, 10) //启用连接池,每个路由最大创建10个链接,总连接数限制为100个
				 .sslpv(SSLProtocolVersion.TLSv1_2) 	//设置ssl版本号,默认SSLv3,也可以调用sslpv("TLSv1.2")
				 .ssl()  	  	//https,支持自定义ssl证书路径和密码,ssl(String keyStorePath, String keyStorepass)
				 .retry(5)		//重试5次
				 ;
	
	HttpClient client = hcb.build();
	
	Map<String, Object> map = new HashMap<String, Object>();
	map.put("key1", "value1");
	map.put("key2", "value2");
	
	//插件式配置请求参数(网址、请求参数、编码、client)
	HttpConfig config = HttpConfig.custom()
	                              .headers(headers)	//设置headers,不需要时则无需设置
	                              .url(url)	          //设置请求的url
	                              .map(map)	          //设置请求参数,没有则无需设置
	                              .encoding("utf-8") //设置请求和返回编码,默认就是Charset.defaultCharset()
	                              .client(client)    //如果只是简单使用,无需设置,会自动获取默认的一个client对象
	                              //.inenc("utf-8")  //设置请求编码,如果请求返回一直,不需要再单独设置
	                              //.inenc("utf-8")	//设置返回编码,如果请求返回一直,不需要再单独设置
	                              //.json("json字符串")                          //json方式请求的话,就不用设置map方法,当然二者可以共用。
	                              //.context(HttpCookies.custom().getContext()) //设置cookie,用于完成携带cookie的操作
	                              //.out(new FileOutputStream("保存地址"))       //下载的话,设置这个方法,否则不要设置
	                              //.files(new String[]{"d:/1.txt","d:/2.txt"}) //上传的话,传递文件路径,一般还需map配置,设置服务器保存路径
	                              ;
	
	
	//使用方式:
	String result1 = HttpClientUtil.get(config);     //get请求
	String result2 = HttpClientUtil.post(config);    //post请求
	System.out.println(result1);
	System.out.println(result2);
	
	//HttpClientUtil.down(config);                   //下载,需要调用config.out(fileOutputStream对象)
	//HttpClientUtil.upload(config);                 //上传,需要调用config.files(文件路径数组)
	
	//如果指向看是否访问正常
	//String result3 = HttpClientUtil.head(config); // 返回Http协议号+状态码
	//int statusCode = HttpClientUtil.status(config);//返回状态码
	
	//[新增方法]sendAndGetResp,可以返回原生的HttpResponse对象,
	//同时返回常用的几类对象:result、header、StatusLine、StatusCode
	HttpResult respResult = HttpClientUtil.sendAndGetResp(config);
	System.out.println("返回结果:\n"+respResult.getResult());
	System.out.println("返回resp-header:"+respResult.getRespHeaders());//可以遍历
	System.out.println("返回具体resp-header:"+respResult.getHeaders("Date"));
	System.out.println("返回StatusLine对象:"+respResult.getStatusLine());
	System.out.println("返回StatusCode:"+respResult.getStatusCode());
	System.out.println("返回HttpResponse对象)(可自行处理):"+respResult.getResp());
}
image 专栏创建者:xiaoxian8023
创建时间:2015-11-16
文章数:17篇
RSS订阅

轻松把玩HttpClient
介绍如何使用HttpClient,通过一些简单示例,来帮助初学者快速入手。
同时提供了一个非常强大的工具类,比现在网络上分享的都强大:
支持插件式设置header、代理、ssl等配置信息,支持携带Cookie的操作,支持http的各种方法,支持上传、下载等功能。

最新更新文章

在Git上有人给我提Issue,说怎么上传文件,其实我一开始就想上这个功能,不过这半年比较忙,所以一直耽搁了。
这次正好没什么任务了,赶紧完成这个功能。毕竟作为一款工具类,有基本的请求和下载功能,就差上...
写了HttpClient工具类后,有人一直在问我怎么启用http连接池,其实我没考虑过这个问题难过。
不过闲暇的时候,突然间想起了这个问题,就想把这个问题搞一搞。
这个HttpClientUtil工具类分享在GitHub上已经半年多的时间了,并且得到了不小的关注,有25颗star,被fork了38次。
有了大家的鼓励,工具类一直也在完善中。最近比较忙,两个多月前的修改在今天刚修改测试完成,今天再次分享给大家。
验证码识别这项技术并不是本工具类的功能,而是通过一个开源的api来识别验证码的。
这里做了一个简单的封装,主要是用来解决登陆时的验证码的问题。...
在写这个工具类的时候发现传入的参数太多,以至于方法泛滥,只一个send方法就有30多个,
所以对工具类进行了优化,把输入参数封装在一个对象里,这样以后再扩展输入参数,直接修改这个类就ok了。
最近更新了一下HttpClientUtil工具类代码,主要是添加了一个参数HttpContext,这个是用来干嘛的呢?
其实是用来保存和传递Cookie所需要的。因为我们有很多时候都需要登录,然后才能请求一些想要的数据。
而在这以前使用HttpClientUtil工具类,还不能办到。现在更新了以后,终于可以了。
先说一下思路:本次的demo,就是获取csdn中的c币,要想获取c币,必须先登...
如果看到过我前些天写过的《轻松把玩HttpClient之模拟post请求示例》这篇文章,你再看本文就是小菜一碟了,如果你顺便懂一些NIO,基本上是毫无压力了。
因为HttpAsyncClient相对于HttpClient,就多了一个NIO,这也是为什么支持异步的原因。
不过我有一个疑问,虽说NIO是同步非阻塞IO,但是HttpAsyncClient提供了回调的机制,
这点儿跟netty很像,所以可以模拟...
本文主要来分享一下该工具类的测试结果。工具类的整体源码不再单独分享,源码基本上都已经在文章中了。
开始我们的测试。单线程调用测试:
    public static void testOne() throws HttpProcessException{
		
		System.out.println("--------简单方式调用(默认post)--------");
		String url = "http://...
上篇文章介绍了插件式配置HttpClient,本文将介绍插件式配置Header。为什么要配置header在前面已经提到了,还里再简单说一下,
要使用HttpClient模拟请求,去访问各种接口或者网站资源,都有可能有各种限制,
比如说java客户端模拟访问csdn博客,就必须设置User-Agent,否则就报错了。
还有各种其他情况,必须的设置一些特定的Header,才能请求成功,或者才能不出问题。好了...
上一篇文章中,简单分享一下封装HttpClient工具类的思路及部分代码,本文将分享如何实现插件式配置HttpClient对象。
如果你看过我前面的几篇关于HttpClient的文章或者官网示例,应该都知道HttpClient对象在创建时,都可以设置各种参数,
但是却没有简单的进行封装,比如对我来说比较重要的3个:
代理、ssl(包含绕过证书验证和自定义证书验证)、超时。还需要自己写。
所以这里我就简单封...
搜了一下网络上别人封装的HttpClient,大部分特别简单,有一些看起来比较高级,但是用起来都不怎么好用。
调用关系不清楚,结构有点混乱。所以也就萌生了自己封装HttpClient工具类的想法。
要做就做最好的,本工具类支持插件式配置Header、插件式配置httpclient对象,
这样就可以方便地自定义header信息、配置ssl、配置proxy等。是不是觉得说的有点悬乎了,那就先看看调用吧:...
前面的文章介绍了一些HttpClient的简单示例,本文继续采用示例的方式来演示HttpClient的功能。
在项目中我们可能会遇到这样的情况:为了保证系统的安全性,只允许使用特定的代理才可以访问,
而与这些系统使用HttpClient进行交互时,只能为其配置代理。
这里我们使用gogent代理访问脸书来模拟这种情况。现在在浏览器上访问是可以访问的:...
在上篇文章《HttpClient配置ssl实现https简单示例——绕过证书验证》中简单分享了一下如何绕过证书验证。
如果你想用httpclient访问一个网站,但是对方的证书没有通过ca认证或者其他问题导致证书不被信任,
比如12306的证书就是这样的。所以对于这样的情况,你只能是选择绕过证书验证的方案了。
但是,如果是自己用jdk或者其他工具生成的证书,还是希望用其他方式认证自签名的证书,这篇文...
上篇文章说道httpclient不能直接访问https的资源,这次就来模拟一下环境,然后配置https测试一下。
在前面的文章中,分享了一篇自己生成并在tomcat中配置ssl的文章《Tomcat配置SSL》,大家可以据此来在本地配置https。
我已经配置好了,效果是这样滴:
可以看到已经信任该证书(显示浅绿色小锁),浏览器可以正常访问。现在我们用代码测试一下:
HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 HTTP 协议最新的版本和建议。
许多需要后台模拟请求的系统或者框架都用的是httpclient。所以作为一个java开发人员,有必要学一学。
本文提供了一个简单的demo,供初学者参考。
这两天在整理看httpclient,然后想自己用UrlConnection后台模拟实现Http请求,于是一个简单的小例子就新鲜出炉了(支持代理哦):
  public class SimpleHttpTest {

	public static String send(String urlStr, Map map,String encoding){
		String body="";
		Strin...

httpclientutil's People

Contributors

arronlong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

httpclientutil's Issues

发送POST请求携带中文参数

发送POST请求携带中文参数会报400错误.
接口接受的是String类型

请求地址:
https://xxxxx/hystrix/user
请求方式:
POST
JSON串:
{
"name":"aaa",
"age":180
}
响应结果:
{"name":"aaa","age":180}

请求地址:
https://xxxxx/hystrix/user
请求方式:
POST
JSON串:
{
"name":"测试",
"age":180
}
响应结果:
{"timestamp":"2020-08-04T04:31:52.593+0000","path":"/hystrix/user","status":400,"error":"Bad Request","message":"Failed to read HTTP message"}

建议增加双向验证

目前只支持客户端信任服务器证书,如果访问时需要携带客户端证书 这种情况没有加载证书的重载方法 建议增加

Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version

Exception in thread "main" com.arronlong.httpclientutil.exception.HttpProcessException: javax.net.ssl.SSLException: Received fatal alert: protocol_version
at com.arronlong.httpclientutil.HttpClientUtil.execute(HttpClientUtil.java:433)
at com.arronlong.httpclientutil.HttpClientUtil.send(HttpClientUtil.java:374)
at com.arronlong.httpclientutil.HttpClientUtil.get(HttpClientUtil.java:102)
at com.arronlong.httpclientutil.test.Demo.main(Demo.java:30)
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.arronlong.httpclientutil.HttpClientUtil.execute(HttpClientUtil.java:422)
... 3 more

第一次访问TLSv1.3的地址会报错,目前发现是打开了线程池的原因

使用作者的demo复现的bug,下载代码后找到test下面的Demo类,注释掉
// //最简单的使用: // String html = HttpClientUtil.get(HttpConfig.custom().url(url).client(HCB.custom().sslpv(SSLProtocolVersion.TLSv1_2).ssl().build())); // System.out.println(html);

然后运行就会报错
Exception in thread "main" com.arronlong.httpclientutil.exception.HttpProcessException: javax.net.ssl.SSLException: Received fatal alert: protocol_version at com.arronlong.httpclientutil.HttpClientUtil.execute(HttpClientUtil.java:462) at com.arronlong.httpclientutil.HttpClientUtil.send(HttpClientUtil.java:377) at com.arronlong.httpclientutil.HttpClientUtil.get(HttpClientUtil.java:102) at com.arronlong.httpclientutil.test.Demo.main(Demo.java:77)

建议作者修复这个bug前,谨慎使用线程池功能

环境为jdk1.8

代码里没有关于TLSv1.3的枚举成语,
SSLProtocolVersion
SSL("SSL"), SSLv3("SSLv3"), TLSv1("TLSv1"), TLSv1_1("TLSv1.1"), TLSv1_2("TLSv1.2"),

发送超大文本数据的时候报错

private static HttpClient client= HCB.custom().timeout(30000*10).build();

{"Code":"xxxxxxx","Date":1450423000000,"dname":"二手","qvpn":"685"} 25000 条。

return HttpClientUtil.send(client,SystemConfiguration.getString("upload.system.api"), paramMap, context, "utf-8");

com.tgb.ccl.http.exception.HttpProcessException: java.net.SocketException: Connection reset by peer: socket write error
at com.tgb.ccl.http.httpclient.HttpClientUtil.execute(HttpClientUtil.java:1536)
at com.tgb.ccl.http.httpclient.HttpClientUtil.send(HttpClientUtil.java:1266)
at com.tgb.ccl.http.httpclient.HttpClientUtil.send(HttpClientUtil.java:999)
at com.tgb.ccl.http.httpclient.HttpClientUtil.send(HttpClientUtil.java:969)

body如何设置

看了lz的所有使用说明没有发现设置body的地方啊

Entity无法使用

使用EntityUtils转换返回的entity时报错,显示使用了已经被关闭的流

调用delete传参有示例吗,这样写是否可行?

	Header[] headers=HttpHeader.custom().userAgent("Mozilla/5.0")
			.contentType(Headers.APP_FORM_URLENCODED).build();  
	HttpConfig config = HttpConfig.custom().headers(headers).url(“https://localhost/message/template.json?appid=12993&signature=a3fcb88e97894ca0674b5a00480f3aa6&template_id=gK0hk2”).encoding("utf-8");
	String res = HttpClientUtil.send(config.method(HttpMethods.DELETE));
	System.out.println(res);

pom.xml

这里面的引入4.4.1版本之后的包的报错了,只有版本4.5.4没有报错。

一些建议想要交流

超时时间

问题

目前设置超时时间都是HCB.custom().timeout(xxx)的方式进行设置,如果是连接池的话,其设置的是该池中所有Http请求的超时时间。而如果我们想要以更低粒度的方式设置超时时间,也就是说为每个连接池的每个Http请求设置不同的超时时间,目前没有办法设置。

解决方案

  1. 添加HttpConfig对象设置超时时间的方法,后面在通过HttpRequestBase对象设置RequestConfig的方式进行设置。
  2. 为HttpConfig添加默认的RequestConfig对象,添加设置该对象的方法,这样粒度更大,用户想要自定义时能够更好的扩展。

执行请求,返回结果

问题

在HttpClientUtil执行Http请求的方法中,方法的粒度太小了,比如我想要Http响应头和Http body的话就没有办法同时拿到。

解决方案

  1. 添加粒度更大的接口进行处理Http请求,可以需要进行把HttpClientUtil执行请求的方法进行重构以便能够更好的使用。

log4j报错

怎么关闭你项目里面那个log4j呢 java.io.FileNotFoundException: /logs/httpclient/httputil.log (No such file or directory)

发现了一些问题

1 SSLs认证使用同步锁,导致开启多个线程实际上只有一个线程在执行。
解决:public SSLConnectionSocketFactory getSSLCONNSF(SSLProtocolVersion sslpv) 取消同步锁
2 请求没设置超时时间。
解决:HttpClientUtil 类中 execute(HttpConfig config)增加超市时间
//创建请求对象
HttpRequestBase request = getRequest(config.url(), config.method());
request.setConfig(RequestConfig.custom().setCircularRedirectsAllowed(true).build());
//设置header信息
request.setHeaders(config.headers());
request.setConfig(RequestConfig.custom().setConnectionRequestTimeout(5000).build());
request.setConfig(RequestConfig.custom().setConnectTimeout(5000).build());

3 代理没设置正确

HCB 类设置代理添加 setProxy(proxy)
public HCB proxy(String hostOrIP, int port) {
// 依次是代理地址,代理端口号,协议类型
HttpHost proxy = new HttpHost(hostOrIP, port, "http");
setProxy(proxy);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
return (HCB) this.setRoutePlanner(routePlanner);
}

302重定向报错

向一个网址发送post请求后,然后网址返回302重定向,我想获取重定向的locations,获取到的是:不支持此消息类型,看不到我想要的东西,这一点怎么解决?

关于传参的一个问题

我用这个调用微信接口。有些接口是推xml数据,不需要key,请问有没有设置的方法
因为我看现在好像只能是推key-value的map

对方为PHP服务器导致请求体空

问题描述:
使用这个请求框架很方便构造,但是遇到了以下的问题(对方服务器后台语言采用PHP):
1.本地windows、本地mac都能请求通并且对方服务器能够正常返回。
2.但是扔到阿里云服务器,对方接收到的请求体就为空,试过对接过很多甲方都是这样。但是甲方使用java语言就能正常使用。

请问这是啥问题。

https 连续请求会出错

单个case运行没问题,连续运行的情况最后一个post请求的map 数据不全,这是为什么
比如
Map<String,Object> formdata=new HashMap<String, Object>(); formdata.put("pageNo","0"); formdata.put("pageSize","20");

但是看请求的info 是只有一个键值对,我的几个case用的是同一个client

多线程问题

目前版本多线程会出现Bug,由于HttpConfig造成的。

关于map传参

HttpConfig config =HttpConfig.custom().url(url)
.map(map)
.method(HttpMethods.GET);
map传参为什么后端接收不到参数。

关于cookies

如果我本地已经获取到了cookies,如何根据cookies来访问登陆的网站。
HttpConfig里面的context和header都设置过了,返回的仍然是没有登陆过的页面

https报错

java.security.cert.CertificateParsingException: X.509 Certificate is incomplete: subject field is empty, and SubjectAlternativeName extension is absent
用https会报这个错

请求 httpsssl报错

Exception in thread "main" com.arronlong.httpclientutil.exception.HttpProcessException: javax.net.ssl.SSLException: Received fatal alert: protocol_version
at com.arronlong.httpclientutil.HttpClientUtil.execute(HttpClientUtil.java:462)
at com.arronlong.httpclientutil.HttpClientUtil.send(HttpClientUtil.java:377)
at com.arronlong.httpclientutil.HttpClientUtil.post(HttpClientUtil.java:128)
at com.github.binarywang.demo.wx.mp.utils.HttpRequestUtilsTest.main(HttpRequestUtilsTest.java:60)
Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version

//最简单的使用:
HCB hcb = HCB.custom()
//.timeout(1000) //超时
.pool(100, 10) //启用连接池,每个路由最大创建10个链接,总连接数限制为100个
.sslpv("TLSv1.2") //可设置ssl版本号,默认SSLv3,用于ssl,也可以调用sslpv("TLSv1.2")
.ssl() //https,支持自定义ssl证书路径和密码,ssl(String keyStorePath, String keyStorepass)
.retry(5) //重试5次
;

    HttpClient client = hcb.build();

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("key1", "value1");
    map.put("key2", "value2");

    //插件式配置请求参数(网址、请求参数、编码、client)
    HttpConfig config = HttpConfig.custom()

        .timeout(1000) 		//超时
        .url(url)           //设置请求的url

// .map(map) //设置请求参数,没有则无需设置
.encoding("utf-8") //设置请求和返回编码,默认就是Charset.defaultCharset()
.client(client) //如果只是简单使用,无需设置,会自动获取默认的一个client对象
//.inenc("utf-8") //设置请求编码,如果请求返回一直,不需要再单独设置
//.inenc("utf-8") //设置返回编码,如果请求返回一直,不需要再单独设置
.json("{\n" +
" "current_openid": "199",\n" +
" "gzhid": "1"\n" +
"\n" +
"}") //json方式请求的话,就不用设置map方法,当然二者可以共用。
//.context(HttpCookies.custom().getContext()) //设置cookie,用于完成携带cookie的操作
//.out(new FileOutputStream("保存地址")) //下载的话,设置这个方法,否则不要设置
//.files(new String[]{"d:/1.txt","d:/2.txt"}) //上传的话,传递文件路径,一般还需map配置,设置服务器保存路径
;

    //使用方式:

    String result2 = HttpClientUtil.post(config);   //post请求

    System.out.println(result2);

connection reset error in https request

HttpConfig config = HttpConfig.custom()
.headers(headers)
.url(iamtokenUrl)
.encoding("utf-8")
.client(HCB.custom().sslpv(SSLs.SSLProtocolVersion.TLSv1_2).ssl().build())
.json(JSON.toJSONString(map));
String result = HttpClientUtil.post(config);

ERROR MESSAGE:
com.arronlong.httpclientutil.exception.HttpProcessException: java.net.SocketException: Connection reset
at com.arronlong.httpclientutil.HttpClientUtil.execute(HttpClientUtil.java:478)
at com.arronlong.httpclientutil.HttpClientUtil.send(HttpClientUtil.java:380)
at com.arronlong.httpclientutil.HttpClientUtil.post(HttpClientUtil.java:131)
at com.caacitc.tcdm.business.imoc.domain.service.impl.ImocOrderImpl.getIamToken(ImocOrderImpl.java:68)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.