开发者

apache client http response to handle status code http 100

I use apache httpdefault client and execute post function as below

HttpResponse imToken = httpClient.execute(httpPostIM);

the response obtained is

HTTP/1.1 100 Continue
Connection: keep-alive

followed by:

开发者_如何学编程HTTP/1.1 200 OK
Date: Tue, 30 Aug 2011 19:11:35 GMT

How do we handle this from client side ??


Here's the definition of response 100 from w3 and here's a good sample of what the response looks like. To quote:

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.

So if your client has already sent the entire request then it should just wait the server out until it gives a 200 or other "final" response.

According to the Apache HttpClient code, you don't have to do anything because the client ignores all 1XX response codes and continues to look for a final response. This is from commons-httpclient-3.1 in the class HttpMethodBase:

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

If you are not seeing this behaviour then maybe you need to increase your client timeout? Maybe it isn't waiting long enough?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜