04_HttpClient发送Https请求
【实例 带Cookie访问HTTPS类型的 建信基金 的某一页面)】
/**
* 创建一个可以访问Https类型URL的工具类,返回一个CloseableHttpClient实例
*/
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();
}
/**
* @throws IOException
* @throws ClientProtocolException
*
*/
public static void main(String[] args) throws ClientProtocolException, IOException {
//从工具方法中获得对应的可以访问Https的httpClient
CloseableHttpClient httpClient =createSSLClientDefault(); HttpGet httpGet=new HttpGet("https://etrade.ccbfund.cn/etrading/tradereq/main.do?method=doInit&isHome=1&menuId=10000");
//自己先在浏览器登录一下,自行复制具体的Cookie
httpGet.setHeader("Cookie", "HS_ETS_SID=4jSFY2wWwT0gPrWJ45ly!-1286216704; Null=31111111.51237.0000; logtype=2; certtype=0; certNo=33****************; isorgloginpage_cookie=0; hs_etrading_customskin=app_css"); //设置代理,方便Fiddle捕获具体信息
RequestConfig config=RequestConfig.custom()
.setProxy(HttpHost.create("127.0.0.1:8888"))
.build();
httpGet.setConfig(config);
//执行get请求,获得对应的响应实例
CloseableHttpResponse response=httpClient.execute(httpGet); //打印响应的到的html正文
HttpEntity entity =response.getEntity();
String html=EntityUtils.toString(entity);
System.out.println(html); //关闭连接
response.close();
httpClient.close();
}
【Fiddler中抓取的内容如下】

【正常登录访问https://etrade.ccbfund.cn/etrading/tradereq/main.do?method=doInit&isHome=1&menuId=10000的页面如下】

【未登录情况访问https://etrade.ccbfund.cn/etrading/tradereq/main.do?method=doInit&isHome=1&menuId=10000的页面如下】

04_HttpClient发送Https请求的更多相关文章
- 【转载】JMeter学习(三十六)发送HTTPS请求
Jmeter一般来说是压力测试的利器,最近想尝试jmeter和BeanShell进行接口测试.由于在云阅读接口测试的过程中需要进行登录操作,而登录请求是HTTPS协议.这就需要对jmeter进行设置. ...
- Web Server 使用WebClient 发送https请求 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel
使用WebClient 发送https请求 使用WebClient发送请求时,并且是以https协议: WebClient webClient = new WebClient(); string re ...
- 使用HttpClient发送HTTPS请求以及配置Tomcat支持SSL
这里使用的是HttpComponents-Client-4.1.2 package com.jadyer.util; import java.io.File; import java.io.FileI ...
- JMeter学习(三十六)发送HTTPS请求(转载)
转载自 http://www.cnblogs.com/yangxia-test Jmeter一般来说是压力测试的利器,最近想尝试jmeter和BeanShell进行接口测试.由于在云阅读接口测试的过程 ...
- 【传输协议】发送https请求,由于客户端jdk版本过高,服务端版本低。导致异常:javax.net.ssl.SSLHandshakeException: Server chose SSLv3, but that protocol version is not enabled or not supported by the client.
本地环境jdk为1.8,服务器使用jdk版本未知.但发送https请求,抛出如下异常,解决方案. 一:发送异常内容如下 javax.net.ssl.SSLHandshakeException: Ser ...
- python2/3 发送https请求时,告警关闭方法
问题: 使用Python3 requests发送HTTPS请求,已经关闭认证(verify=False)情况下,控制台会输出以下错误: InsecureRequestWarning: Unverifi ...
- requests发送HTTPS请求(处理SSL证书验证)
1.SSL是什么,为什么发送HTTPS请求时需要证书验证? 1.1 SSL:安全套接字层.是为了解决HTTP协议是明文,避免传输的数据被窃取,篡改,劫持等. 1.2 TSL:Transport Lay ...
- .Net Core 发送https请求/.net core 调用数字证书 使用X509Certificate2
.Net Core 发送https请求 .net core 调用数字证书 使用X509Certificate2 .NET下面的 .netfromwork使用和asp.net core下使用方式不一样 ...
- 简单粗暴套娃模式组json发送https请求
各位童鞋大家好,向来简单粗暴的铁柱兄给大家来玩一手套娃模式来组Json数据,不说别的,无脑套. 当然,这一手比较适合临场用一下,若长期用的话建议搞一套适用的框架,只管set就好了.话不多说开始上课. ...
随机推荐
- jquery基础篇
1.jquery选择器和css选择器的关系: jquery的选择器是源于css,jquery支持css1和css2的全部和css3 的部分选择器,同时它也有少量独有的选择器. 2.常用jquery选择 ...
- PHP魔术变量总结
php手册里面的解释 __FUNCTION__ returns only the name of the function 返回的仅仅是函数的名称 __METHOD__ returns t ...
- Oracle- 正则表达式查询
发现Oracle支持正则表达式.先收藏. ORACLE中的支持正则表达式的函数主要有下面四个:1,REGEXP_LIKE :与LIKE的功能相似2,REGEXP_INSTR :与INSTR的功能相似3 ...
- WIN32进阶必备:跟随鼠标移动的子窗口
上两张Demo的图,方便朋友们选择是否继续看文章. 在子窗口的白色区域按下鼠标左键不放并移动鼠标可以拖拽子窗口跟随鼠标移动. 选择继续看下去的朋友不要担心,接下来就是正文了. PART 1:Demo功 ...
- 实现windows和linux互传文件
http://www.cnblogs.com/ylan2009/archive/2012/01/12/2321126.html 尝试从windows xp向ubuntu11.10传文件 ubuntu使 ...
- iOS之FMDB 转载
写的较好的博客:http://blog.csdn.net/xyz_lmn/article/details/9312837 http://www.cnblogs.com/wuhenke/archiv ...
- [React Native] Complete the Notes view
In this final React Native lesson of the series we will finalize the Notes view component and squash ...
- [Bootstrap] 8. 'Collapse', data-target, data-toggle & data-parent
Using Bootstrap JavaScript Plugins If we want to add behavior to our website, which of the following ...
- 关于Log4j的初始化
1Log4j是什么 Log4j是Apache比較优秀的开源项目.在各个平台和项目中有较为广泛的应用.是为JAVA平台开发的日志管理平台.同一时候,Log4j也是JAVA开发项目中使用比較普遍的日 ...
- offsetTop和scrollTop的差别
近期想写个组件,结果被这两个属性搞的有点晕,查了下文档和资料,对这两个属性总结例如以下: 一直以来对offsetLeft,offsetTop,scrollLeft,scrollTop这几个方法非常迷糊 ...