java中模拟浏览器发送https请求报错:Server sent an unsupported extension: type_35

suixixiang8140 2017-11-14 09:24:32

public static String formPost(String url,String params){
String responseMessage = "";
StringBuffer response = new StringBuffer();
HttpURLConnection httpConnection = null;
OutputStreamWriter out = null;
BufferedReader reader = null;
try {
URL urlPost = new URL(url);
httpConnection = (HttpURLConnection) urlPost.openConnection();
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true);
// 参数长度太大,不能用get方式
httpConnection.setRequestMethod("POST");
// 不使用缓存
httpConnection.setUseCaches(false);
// URLConnection.setInstanceFollowRedirects是成员函数,仅作用于当前函数
httpConnection.setInstanceFollowRedirects(true);
httpConnection.setRequestProperty("Connection", "Keep-Alive");
// 设置请求头信息
httpConnection.setRequestProperty("Charset", "UTF-8");
// 设置边界
//httpConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");


httpConnection.connect(); ///////这行报错
out = new OutputStreamWriter(httpConnection.getOutputStream(),"UTF-8");
// 构建请求参数
StringBuffer sb = new StringBuffer();
sb.append(params);
out.write(sb.toString());
System.out.println("send_url:" + url);
System.out.println("send_data:" + sb.toString());
// flush and close
out.flush();

} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != out) {
out.close();
}
if (null != reader) {
reader.close();
}
if (null != httpConnection) {
httpConnection.disconnect();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}

try {
reader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(),"UTF-8"));
while ((responseMessage = reader.readLine()) != null) {
response.append(responseMessage);
response.append("\n");
}

if (!"failure".equals(response.toString())) {
System.out.println("post链接success");
} else {
System.out.println("post链接failue");
}
// 将该url的配置信息缓存起来
return response.toString();
} catch (IOException e) {
e.printStackTrace();
return response.toString();
}
}


用https请求头,随便访问一个网址都不行,http就可以

public static void main(String[] args) {
formPost("https://www.baidu.com", "");
}

发第一次叫我升级jdk的,我已经试了,已经卸载重装升级过jdk了 ,现在是jdk1.8还是报一样的错;
之前都是一直可以用的,做过测试也没问题,忘记改了什么东西之后就没有用了。
下面是报错信息

javax.net.ssl.SSLHandshakeException: Server sent an unsupported extension: type_35
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:292)
at sun.security.ssl.ClientHandshaker.serverHello(ClientHandshaker.java:656)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:206)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:162)
at com.wechat.util.ledou.LedouUtil.formPost(LedouUtil.java:93)
at com.wechat.util.ledou.LedouUtil.main(LedouUtil.java:344)
javax.net.ssl.SSLException: Server selected improper ciphersuite TLS_ECDHE_RSA_WITH_RC4_128_SHA
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:292)
at sun.security.ssl.ClientHandshaker.serverHello(ClientHandshaker.java:534)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:206)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at com.wechat.util.ledou.LedouUtil.formPost(LedouUtil.java:123)
at com.wechat.util.ledou.LedouUtil.main(LedouUtil.java:344)


...全文
973 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
这日子不在绿 2019-05-02
  • 打赏
  • 举报
回复
都按哪位大神做了还是没解决,坑爹啊
suixixiang8140 2018-03-20
  • 打赏
  • 举报
回复
引用 3 楼 tianfang 的回复:
解决办法: 编辑Java\jdk1.8.0_151\jre\lib\security\java.security JRE路径下也有一个 Java\jre1.8.0_151\lib\security\java.security 其中给出了例子,把屏蔽的算法加入进允许的算法中即可,重新启动java程序,如eclipse,tomcat

# Example:
#   jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
jdk.tls.legacyAlgorithms= \
        K_NULL, C_NULL, M_NULL, \
        DHE_DSS_EXPORT, DHE_RSA_EXPORT, DH_anon_EXPORT, DH_DSS_EXPORT, \
        DH_RSA_EXPORT, RSA_EXPORT, \
        DH_anon, ECDH_anon, \
        RC4_128, RC4_40, DES_CBC, DES40_CBC, \
        3DES_EDE_CBC
大哥,我弄好了。真的太谢谢你,这个问题困扰我半年了!你是真的强,大佬。
suixixiang8140 2018-03-20
  • 打赏
  • 举报
回复
引用 3 楼 tianfang 的回复:
解决办法: 编辑Java\jdk1.8.0_151\jre\lib\security\java.security JRE路径下也有一个 Java\jre1.8.0_151\lib\security\java.security 其中给出了例子,把屏蔽的算法加入进允许的算法中即可,重新启动java程序,如eclipse,tomcat

# Example:
#   jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
jdk.tls.legacyAlgorithms= \
        K_NULL, C_NULL, M_NULL, \
        DHE_DSS_EXPORT, DHE_RSA_EXPORT, DH_anon_EXPORT, DH_DSS_EXPORT, \
        DH_RSA_EXPORT, RSA_EXPORT, \
        DH_anon, ECDH_anon, \
        RC4_128, RC4_40, DES_CBC, DES40_CBC, \
        3DES_EDE_CBC
引用 3 楼 tianfang 的回复:
解决办法: 编辑Java\jdk1.8.0_151\jre\lib\security\java.security JRE路径下也有一个 Java\jre1.8.0_151\lib\security\java.security 其中给出了例子,把屏蔽的算法加入进允许的算法中即可,重新启动java程序,如eclipse,tomcat

# Example:
#   jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
jdk.tls.legacyAlgorithms= \
        K_NULL, C_NULL, M_NULL, \
        DHE_DSS_EXPORT, DHE_RSA_EXPORT, DH_anon_EXPORT, DH_DSS_EXPORT, \
        DH_RSA_EXPORT, RSA_EXPORT, \
        DH_anon, ECDH_anon, \
        RC4_128, RC4_40, DES_CBC, DES40_CBC, \
        3DES_EDE_CBC
大佬大佬,我这好久没看自己的帖子了,看你这个解决办法好像是有用的样子,但是这里我应该怎么操作呢?怎么让它允许呢?我小白一个,求大神指点!
tianfang 2017-11-15
  • 打赏
  • 举报
回复
解决办法: 编辑Java\jdk1.8.0_151\jre\lib\security\java.security JRE路径下也有一个 Java\jre1.8.0_151\lib\security\java.security 其中给出了例子,把屏蔽的算法加入进允许的算法中即可,重新启动java程序,如eclipse,tomcat

# Example:
#   jdk.tls.legacyAlgorithms=DH_anon, DES_CBC, SSL_RSA_WITH_RC4_128_MD5
#
jdk.tls.legacyAlgorithms= \
        K_NULL, C_NULL, M_NULL, \
        DHE_DSS_EXPORT, DHE_RSA_EXPORT, DH_anon_EXPORT, DH_DSS_EXPORT, \
        DH_RSA_EXPORT, RSA_EXPORT, \
        DH_anon, ECDH_anon, \
        RC4_128, RC4_40, DES_CBC, DES40_CBC, \
        3DES_EDE_CBC
tianfang 2017-11-15
  • 打赏
  • 举报
回复
又找了一下 jdk8屏蔽了RC4算法 http://www.oracle.com/technetwork/java/javase/8all-relnotes-2226344.htm 8u51: Synopsis: Deprecate RC4 in SunJSSE provider 8u60: Synopsis: Disable RC4 cipher suites
tianfang 2017-11-15
  • 打赏
  • 举报
回复
安装jdk8 的jce,下载后,按其中的说明安装 http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧