Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请求 httpsssl报错 #53

Open
jornsky opened this issue Aug 31, 2021 · 0 comments
Open

请求 httpsssl报错 #53

jornsky opened this issue Aug 31, 2021 · 0 comments

Comments

@jornsky
Copy link

jornsky commented Aug 31, 2021

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant