我使用 apache httpdefault 客户端并执行如下的 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
我们如何从客户端处理这个问题??
最佳答案
这是 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;
}
如果您没有看到此行为,那么您可能需要增加客户端超时时间?也许是等待的时间不够长?
关于java - apache 客户端 http 响应处理状态码 http 100,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7249210/