开发者社区> 问答> 正文

httpclient.executeMethod?报错

通过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端口都是通的。

对网络不了解了……

展开
收起
爱吃鱼的程序员 2020-06-22 21:17:33 1819 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    很有可能啊,服务器接收了请求但是一直堵塞。你可以设置个超时,在getParams返回的对象里有方法
    为什么会堵塞呢?是很可能,因为我用httpclient试了下,调用jar包里的方法尝试就是readtimeout。非常怀疑是网络的问题。但是服务器那边没有错误日志……试试网络抓包··看你发送出去没·遇到类似的问题,请问是怎么解决的

    2020-06-22 21:17:49
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载