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

标签 java httpclient

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

相关文章:

java - 如何在 Axis 中禁用 SSLv2 套接字协议(protocol)

c# - 使用 Ms Graph 更新日历事件在 Start end End 属性中使用了错误的时区

c# - HttpClient 下载文件 OutOfMemory 错误

JAVA:http post 请求

java - HTTP/1.1 400 错误请求 Apache

java - 在 Android 应用程序中使用 ResourceBundle.getBundle() 的正确方法是什么?

java - 编译器对我在 Java 中的泛型不满意

java - 使用 Apache HTTPAsyncClient 针对每个 HTTPS 请求自定义 SSLContext

java - 将 Spring 服务公开为 SOAP web 服务

java - 为什么Java在System32中找不到这个文件?