javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection

客户端向服务器发送数据时,份两种情况,SSL单向验证和SSL双向验证

1.SSL单向验证时

代码如下:

Java代码  

  1. import java.io.IOException;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import org.apache.commons.httpclient.HttpClient;
  5. import org.apache.commons.httpclient.HttpException;
  6. import org.apache.commons.httpclient.HttpStatus;
  7. import org.apache.commons.httpclient.NameValuePair;
  8. import org.apache.commons.httpclient.methods.PostMethod;
  9. import org.apache.commons.httpclient.params.HttpClientParams;
  10. import org.apache.commons.httpclient.params.HttpMethodParams;
  11. import org.apache.commons.logging.Log;
  12. import org.apache.commons.logging.LogFactory;
  13. public class ClientSendData {
  14. static Log log = LogFactory.getLog(ClientSendData.class);
  15. private String Url;
  16. // 初始化数据
  17. public ClientSendData() {
  18. Url = "https://test.yihaodian.com:8443/ims/feedbackToPingAn_getData.action";
  19. }
  20. public String sendData(String data) {
  21. String receivedData = null;
  22. try {
  23. Map<String, String> paramsData = new HashMap<String, String>();
  24. paramsData.put("data", data);
  25. receivedData = send(Url, paramsData);
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29. return receivedData;
  30. }
  31. public static String send(String url, Map<String, String> paramsMap) {
  32. String result = null;
  33. PostMethod postMethod = null;
  34. HttpClient httpClient = new HttpClient();
  35. httpClient.getParams().setParameter(
  36. HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
  37. postMethod = new PostMethod(url);
  38. if (paramsMap != null && paramsMap.size() > 0) {
  39. NameValuePair[] datas = new NameValuePair[paramsMap.size()];
  40. int index = 0;
  41. for (String key : paramsMap.keySet()) {
  42. datas[index++] = new NameValuePair(key, paramsMap.get(key));
  43. }
  44. postMethod.setRequestBody(datas);
  45. }
  46. HttpClientParams httparams = new HttpClientParams();
  47. httparams.setSoTimeout(60000);
  48. postMethod.setParams(httparams);
  49. try {
  50. int statusCode = httpClient.executeMethod(postMethod);
  51. if (statusCode == HttpStatus.SC_OK) {
  52. result = postMethod.getResponseBodyAsString();
  53. log.info("发送成功!");
  54. } else {
  55. log.error(" http response status is " + statusCode);
  56. }
  57. } catch (HttpException e) {
  58. log.error("error url=" + url, e);
  59. } catch (IOException e) {
  60. log.error("error url=" + url, e);
  61. } finally {
  62. if (postMethod != null) {
  63. postMethod.releaseConnection();
  64. }
  65. }
  66. return result;
  67. }
  68. public static void main(String[] args) {
  69. ClientSendData t = new ClientSendData();
  70. t.sendData("测试SSL单项连接,向服务端发送数据!");
  71. }
  72. }

可能出现的异常

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如何在双向验证时发送数据的,恳请指教。

时间: 2024-08-03 23:00:08

javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection的相关文章

httpclient信任所有证书解决SSLException:Unrecognized SSL message,plaintext connection

在使用 HttpClient 工具调用第三方 Http 接口时报错 javax.net.ssl.SSLException:Unrecognized SSL message,plaintext connection? 这个错误意思是说,无法识别 SSL 信息,明文连接? 看这个意思是说在使用 https 协议访问网络资源时无法识别 SSL 信息. SSL(Secure Socket Layer 安全套接层)是基于HTTPS下的一个协议加密层,最初是由网景公司(Netscape)研发,后被IETF(

微信证书 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

这几天在做微信退款接口,按照api写完之后,在本地测试了下没有问题,于是交给测试让他们在测试环境开测.他们说退款没有成功,感觉去查日志,发现后台报了 javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty .退款证书没

javax.net.ssl.SSLException: hostname in certificate didn&#39;t match:

每个协议有自己的一套SSL东西,Android 链接https经常会抛出如下错误 javax.net.ssl.SSLException: hostname in certificate didn't match: <test.rigbee.cn> != <rigbee.cn> OR <rigbee.cn> OR <www.rigbee.cn> at org.apache.http.conn.ssl.AbstractVerifier.verify(Abstra

jvax.net.ssl.SSLException: 异常解决

后台报错抛出异常:javax.net.ssl.SSLException: Server selected improper ciphersuite SSL_RSA_WITH_DES_CBC_SHAat sun.security.ssl.Alerts.getSSLException(Unknown Source)at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)at sun.security.ssl.Handshaker.fatalSE(

在阿里云linux下使用SVN访问VisualSVN出错:SSL handshake failed: SSL error: Key usage violation in certificate has been detected

Subversion clients receive the following error message when attempting to connect to VisualSVN Server: svn: OPTIONS of 'https://server.domain.local/svn/repo': SSL handshake failed: SSL error:Key usage violation in certificate has been detected. (http

解决Linux下Svn检出Windows SVN服务器上项目SSL handshake failed: SSL error: Key usage violation in certificate has been detected.

在Linux上检出windows SVN服务器上项目时出现了SSL handshake failed: SSL error: Key usage violation in certificate has been detected.的错误. 最后通过从网上检索找到了一个答案: 可以同时解决掉在Ubuntu上和CentOS上检出失败的问题. 在Windows注册表中加入注册项: 32位机器: [HKEY_LOCAL_MACHINE\SOFTWARE\VisualSVN\VisualSVN Serv

免费SSL证书 Free SSL

中国证书CHINASSL 提供2款免费试用SSL证书,试用SSL证书和正式签发的SSL证书功能和兼容性没有任何区别,用户可以用于在申请正式SSL证书前测试服务器环境,模拟SSL证书申请配置流程,免费SSL证书由系统全自动签发,无需人工干预,您可以随时申请试用SSL证书,无需联系客服.目前提供2款免费试用SSL证书产品,一款为COMODO SSL证书,另一款是RapidSSL SSL证书,欢迎用户测试安装! 免费SSL证书申请地址:http://www.chinassl.net/free_ssl/

LNMP(Nginx负载均衡,SSL原理,Nginx配置SSL,生产SSL密钥对)

一.Nginx负载均衡 负载均衡:单从字面上的意思来理解就可以解释N台服务器平均分担负载,不会因为某台服务器负载高宕机而某台服务器闲置的情况.那么负载均衡的前提就是要有多台服务器才能实现,也就是两台以上即可. 在开始部署负载均衡之前,我们先来介绍一个命令,dig命令需要yum安装一下 [[email protected] ~]# yum install bind-utils [[email protected] ~]# dig qq.com            (dig后加域名,他可以返回2个

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

# 背景 安装pip后发现执行pip install pytest,提示下面错误 pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. # 解决方法 查询了资料,大概意思是,新版的pip默认要使用SSL,可以通过设置修改,但木有发现pip.conf文件在哪里,囧rz,后续再研究下 但找到另外一个解决方法 先安装openssl-dev,然后重