通过httpclient向服务器发送https请求,可是连接报错。
// 构造HttpClient的实例 HttpClient httpClient = new HttpClient(); GetMethod getMethod = new GetMethod(ssoInterfactUrl); // 设置连接超时和读取超时 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(30000); httpClient.getHttpConnectionManager().getParams().setSoTimeout(30000); try { WmsvrUtils.log("start"); int statusCode = httpClient.executeMethod(getMethod); WmsvrUtils.log("statusCode" + statusCode); if (statusCode != HttpStatus.SC_OK) { WmsvrUtils.log("Method failed:" + getMethod.getStatusLine()); } byte[] responseBody = getMethod.getResponseBody(); ssoVerifyString = new String(responseBody); } catch (HttpException e) { WmsvrUtils.log("[zjgfsso] Please check your provided http address!", e); } catch (IOException e) { WmsvrUtils.log("[zjgfsso] network error", e); } finally { // 释放连接 getMethod.releaseConnection(); }
按@红薯 的建议增加了超时,报错如下:
18:31:21 INFO [tid:16] [zjgfsso] network error java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(Unknown Source) at com.sun.net.ssl.internal.ssl.InputRecord.readFully(Unknown Source) at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source) at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source) at java.io.BufferedInputStream.fill(Unknown Source) at java.io.BufferedInputStream.read(Unknown Source) at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78) at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106) at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116) at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at org.apache.jsp.cmcu_005faddon.zjgfLogin_jsp._jspService(zjgfLogin_jsp.java:184) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.tebie.cmapp.ajxvr.JSPFilter.doFilter(SourceFile:102) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:856) at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565) at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509) at java.lang.Thread.run(Unknown Source)
服务器端到底在干什么……
好伤心啊,我们是客户端,通过webservice传递请求,可是试了两种完全不同的实现,都是read time out。问他们服务器的负责人,他们说服务器没有日志…… webservice地址是https的,证书我已经加了。通过浏览器可以打开https连接,telnet 80 和 443端口都是通的。
对网络不了解了……
很有可能啊,服务器接收了请求但是一直堵塞。你可以设置个超时,在getParams返回的对象里有方法
为什么会堵塞呢?是很可能,因为我用httpclient试了下,调用jar包里的方法尝试就是readtimeout。非常怀疑是网络的问题。但是服务器那边没有错误日志……试试网络抓包··看你发送出去没·遇到类似的问题,请问是怎么解决的
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。