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

发布于 2024-12-02 07:40:40 字数 330 浏览 0 评论 0原文

我使用 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

我们如何从客户端处理这个问题?

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 ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-12-09 07:40:40

这是 来自 w3 的响应 100 的定义,这是 < a href="http://www.jmarshall.com/easy/http/#http1.1c4" rel="nofollow">响应内容就像。引用:

客户端应该继续其请求。此临时响应用于通知客户端请求的初始部分已收到并且尚未被服务器拒绝。客户端应该继续发送请求的其余部分,或者如果请求已经完成,则忽略此响应。服务器必须在请求完成后发送最终响应。有关此状态代码的使用和处理的详细讨论,请参阅第 8.2.3 节。

因此,如果您的客户端已经发送了整个请求,那么它应该等待服务器,直到它给出 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;
}

如果您没有看到此行为,那么也许您需要增加客户端超时?或许是等待的时间还不够长?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文