有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java apache客户端http响应以处理状态代码http 100

我使用ApacheHttpDefault客户端并执行post函数,如下所示

HttpResponse imToken = httpClient.execute(httpPostIM);

得到的响应是

HTTP/1.1 100 Continue
Connection: keep-alive

其次是:

HTTP/1.1 200 OK
Date: Tue, 30 Aug 2011 19:11:35 GMT

我们如何从客户端处理此问题


共 (1) 个答案

  1. # 1 楼答案

    这是response 100 from w3的定义,这是what the response looks like的一个很好的例子。引述:

    The client SHOULD continue with its request. This interim response is used to inform the client that the initial part of the request has been received and has not yet been rejected by the server. The client SHOULD continue by sending the remainder of the request or, if the request has already been completed, ignore this response. The server MUST send a final response after the request has been completed. See section 8.2.3 for detailed discussion of the use and handling of this status code.

    因此,如果您的客户端已经发送了整个请求,那么它应该等待服务器发出200或其他“最终”响应

    根据Apache HttpClient代码,您不必做任何事情,因为客户端忽略所有1XX响应代码并继续寻找最终响应。这是来自类HttpMethodBase中的commons-httpclient-3.1

    if ((status >= 100) && (status < 200)) {
        if (LOG.isInfoEnabled()) {
            LOG.info("Discarding unexpected response: " +
                this.statusLine.toString()); 
        }
        this.statusLine = null;
    }
    

    如果您没有看到这种行为,那么您可能需要增加客户端超时?也许等待的时间不够长