SSL连接出现的问题
客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证
1.SSL单向验证时
代码如下:
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import org.apache.commons.httpclient.HttpClient;
- import org.apache.commons.httpclient.HttpException;
- import org.apache.commons.httpclient.HttpStatus;
- import org.apache.commons.httpclient.NameValuePair;
- import org.apache.commons.httpclient.methods.PostMethod;
- import org.apache.commons.httpclient.params.HttpClientParams;
- import org.apache.commons.httpclient.params.HttpMethodParams;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- public class ClientSendData {
- static Log log = LogFactory.getLog(ClientSendData.class);
- private String Url;
- // 初始化数据
- public ClientSendData() {
- Url = "https://test.yihaodian.com:8443/ims/feedbackToPingAn_getData.action";
- }
- public String sendData(String data) {
- String receivedData = null;
- try {
- Map<String, String> paramsData = new HashMap<String, String>();
- paramsData.put("data", data);
- receivedData = send(Url, paramsData);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return receivedData;
- }
- public static String send(String url, Map<String, String> paramsMap) {
- String result = null;
- PostMethod postMethod = null;
- HttpClient httpClient = new HttpClient();
- httpClient.getParams().setParameter(
- HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
- postMethod = new PostMethod(url);
- if (paramsMap != null && paramsMap.size() > 0) {
- NameValuePair[] datas = new NameValuePair[paramsMap.size()];
- int index = 0;
- for (String key : paramsMap.keySet()) {
- datas[index++] = new NameValuePair(key, paramsMap.get(key));
- }
- postMethod.setRequestBody(datas);
- }
- HttpClientParams httparams = new HttpClientParams();
- httparams.setSoTimeout(60000);
- postMethod.setParams(httparams);
- try {
- int statusCode = httpClient.executeMethod(postMethod);
- if (statusCode == HttpStatus.SC_OK) {
- result = postMethod.getResponseBodyAsString();
- log.info("发送成功!");
- } else {
- log.error(" http response status is " + statusCode);
- }
- } catch (HttpException e) {
- log.error("error url=" + url, e);
- } catch (IOException e) {
- log.error("error url=" + url, e);
- } finally {
- if (postMethod != null) {
- postMethod.releaseConnection();
- }
- }
- return result;
- }
- public static void main(String[] args) {
- ClientSendData t = new ClientSendData();
- t.sendData("测试SSL单项连接,向服务端发送数据!");
- }
- }
可能出现的异常
1.java.net.ConnectException: Connection refused: connect
服务器没有启动
2 .javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed
服务端的证书是不可信的。解决办法见这篇文章 http://zhuyuehua.iteye.com/blog/1102347
3.java.net.SocketException: Software caused connection abort: recv failed
这是由于服务端配置的是SSL双向认证,而客户端发送数据是按照服务器是单向认证时发送的,即没有将客户端证书信息一起发送给服务端。
4.org.apache.commons.httpclient.NoHttpResponseException
这一般是服务端防火墙的原因。拦截了客户端请求。
另外,当服务端负载过重时,也会出现此问题。
5.javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
这是由于服务端配置的是SSL双向认证,而客户端发送数据是按照服务器是单向认证时发送的,即没有将客户端证书信息一起发送给服务端。服务端验证客户端证书时,发现客户端没有证书,然后就断开了握手连接。
2.SSL双向验证时
双向验证时,暂时不知道如何用HTTPCLIENT发送数据,如需要双向验证时发送数据,参考我另外的文章。另外,有知道HTTPCLIENT如何在双向验证时发送数据的,恳请指教。
SSL连接出现的问题的更多相关文章
- 无法建立SSL连接
在使用wget工具的过程中,当URL使用HTTPS协议时,经常出现如下错误:“无法建立SSL连接”. 这是因为wget在使用HTTPS协议时,默认会去验证网站的证书,而这个证书验证经常会失败.加上&q ...
- 使用sslsplit嗅探tls/ssl连接
首先发一个从youtube弄到的sslsplit的使用教程 http://v.qq.com/page/x/k/s/x019634j4ks.html 我最近演示了如何使用mitmproxty执行中间人攻 ...
- 使用 JSSE 定制 SSL 连接的属性--转载
当数据在网络上传播的时候,通过使用 SSL 对其进行加密和保护,JSSE 为 Java 应用程序提供了安全的通信.在本篇有关该技术的高级研究中,Java 中间件开发人员 Ian Parkinson 深 ...
- 在linux下的apache配置https协议,开启ssl连接
环境:linux 配置https协议,需要2大步骤: 一.生成服务器证书 1.安装openssl软件 yum install -y openssl mod_ssl 2.生成服务器私匙,生成server ...
- 为ownCloud配置SSL连接
为ownCloud配置SSL连接 在你开始使用ownCloud之前,强烈建议你在ownCloud中启用SSL支持.使用SSL可以提供重要的安全好处,比如加密ownCloud流量并提供适当的验证.在本教 ...
- python安装的时候报SSL连接错误的解决办法
Collecting xlwt Could not fetch URL https://pypi.python.org/simple/xlwt/: There was a problem conf ...
- java ssl 连接AD域
1.安装证书服务和IIS服务,不需要启动asp.(其会在c盘生成一个crt文件)2.获取crt证书文件 windows 2003:文件位于系统盘根目录 windows 2008: 文件位于C:\Win ...
- Mysql ssl 连接
在Azure创建了一个Mysql5.7服务,因为默认使用ssl连接,需要下载Azure的证书,并使用openssl生成客户端的证书.具体流程参考官方文档 大致步骤: 下载根证书, 安装openssl, ...
- 苹果电脑利用wget总是会出现无法建立 SSL 连接的问题
在做迁徙学习的过程中,需要下载已经训练好的Inception_v3模型,首先我们为了将下载的模型保存到指定的地方,我们需要利用 wget -P 想要保存的目录 模型的网址,例如 wget -P /Vo ...
- java连接数据库报了ssl连接的警告
警告内容:Establishing SSL connection without server's identity verification is not recommended(不建议在没有服务器 ...
随机推荐
- USTC现代软件工程--summary
起笔:我希望先简单总结一下我在这门课程中经历的一些工作以及学习到的一些东西,再对自己.队友.老师做一个评价.然后我想提出一些对这门课程的一些看法和建议,与自己的心得体会. 第一部分: 我在这门课上经历 ...
- 【Leetcode周赛】从contest-41开始。(一般是10个contest写一篇文章)
Contest 41 ()(题号) Contest 42 ()(题号) Contest 43 ()(题号) Contest 44 (2018年12月6日,周四上午)(题号653—656) 链接:htt ...
- center os 下redis安装以及基本使用
解压并进入其目录 make cd src make install 默认情况,Redis不是在后台运行,我们需要把redis放在后台运行 vim /usr/local/redis/etc/redis. ...
- Hadoop的配置文件
hadoop-env.sh:脚本中所用到的环境变量,以运行Hadoop mapred-env.sh:脚本中所用到的环境变量,以运行mapreduce yarn-env.sh:脚本中所用到的环境变量,以 ...
- springboot 操作redis
redis五大类型用法 Redis五大类型:字符串(String).哈希/散列/字典(Hash).列表(List).集合(Set).有序集合(sorted set)五种Controller:@Reso ...
- 【leetcode】878. Nth Magical Number
题目如下: 解题思路:本题求的是第N个Magical Number,我们可以很轻松的知道这个数的取值范围 [min(A,B), N*max(A,B)].对于知道上下界求具体数字的题目,可以考虑用二分查 ...
- QT中视图(setViewport)和窗口(setWindow) 小总结
参考博客: https://blog.csdn.net/weixin_39583140/article/details/92798127 https://blog.csdn.net/u01244271 ...
- js 事件对象event
在触发DOM上的某个事件时,会产生一个事件对象event.这个对象中包含着所有与事件有关的信息.包括导致事件的元素,事件的类型以及其他与特定事件相关的信息. <body> <a hr ...
- git查看切换分支
Git一般有很多分支,我们clone到本地的时候一般都是master分支,那么如何切换到其他分支呢?主要命令如下: 1. 查看远程分支 $ git branch -a 我在mxnet根目录下运行以上命 ...
- Bugku | Easy_vb
载入ida,直接搜‘ctf’就有了,坑点是不要交“MCTF{XXX}”,要交“flag{XXXX}”