httpClient4.3发送https请求
来源:互联网 发布:淘宝评论没有了 编辑:程序博客网 时间:2024/06/06 17:05
首先创建一个工具类:
public class HttpClientUtil {public static CloseableHttpClient createSSLClientDefault() {try {SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {// 信任所有public boolean isTrusted(X509Certificate[] chain,String authType) throws CertificateException {return true;}}).build();SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext);return HttpClients.custom().setSSLSocketFactory(sslsf).build();} catch (KeyManagementException e) {e.printStackTrace();} catch (NoSuchAlgorithmException e) {e.printStackTrace();} catch (KeyStoreException e) {e.printStackTrace();}return HttpClients.createDefault();}}
在自己的程序中调用:
public static void main(String[] args) throws Exception {CloseableHttpClient client = HttpClientUtil.createSSLClientDefault();HttpGet get = new HttpGet("https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2014-06-18&leftTicketDTO.from_station=WHN&leftTicketDTO.to_station=IZQ&purpose_codes=ADULT");CloseableHttpResponse response = client.execute(get);HttpEntity entity = response.getEntity();InputStream input = entity.getContent();OutputStream output = new FileOutputStream("D:/dat.txt");int len = 0;byte[] buff = new byte[1024];while(-1!=(len = input.read(buff))){output.write(buff, 0,len);}}
0 0
- httpClient4.3发送https请求
- httpClient4.1发送https报文请求,带证书,签名
- httpClient4.1发送https报文请求,带证书,签名
- httpclient4.x 使用连接池发送https请求使用总结
- httpclient4.x 使用连接池发送https请求
- HttpClient4.3.3 https请求
- HttpClient4.3 关于https 中SSL证书请求问题
- HttpClient4.3实现https请求信任所有证书
- HttpClient4.5发送post请求
- (转) httpclient4.x 使用连接池发送https请求使用总结
- Java使用HttpClient4.3发送GET/POST请求
- HttpClient4.3.x请求https的解决方案
- httpclient4.x处理https协议请求
- Qt 发送 https 请求
- java 发送 https请求
- Qt 发送 https 请求 .
- java发送https请求
- HTTPClient 发送HTTPS请求
- Eclipse SDK中一些插件的安装(web开发插件)
- mysql数据仓库指南
- 中国天气网天气图例
- UVa 10041 - Vito's Family
- acdream Number theory
- httpClient4.3发送https请求
- Android工具包AndroidUtils
- Java基础回顾_instanceof运算符_属于
- poj 2478 Farey Sequence(基于素数筛法求欧拉函数)
- 每日算法之三十四:Multiply Strings
- ,成为JVM平台的忠实拥趸,
- “svn: Can't convert string from 'UTF-8' to native encoding” 错误
- Socket的阻塞模式和非阻塞模式
- 解决mysql忘记root密码