- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Apache HttpClient 4.5.1 向我们的服务器发送一些请求。为了提高性能,我想为所有这些请求重用相同的 HttpClient 实例。请求(大部分)按顺序发生,因此不涉及多线程。
不幸的是,某些服务器端点出现故障。他们返回 HTTP 204(无内容),但响应正文中仍然有一些数据。尽管这已在最新版本中得到修复,但我们将不得不在相当长的一段时间内处理旧版本。此服务器行为导致 HTTP 客户端在下一个请求时“挂起”(/超时)(有关详细信息,请参阅 Every second request using Apache HTTPClient fails)。
有没有办法在客户端解决这个问题?我试过了
HttpEntity entity = response.getEntity();
if (null != entity) {
EntityUtils.consumeQuietly(entity);
}
但实体似乎为空,所以我无法使用卡在连接套接字中的响应数据。有没有另一种方法可以在不丢弃 HttpClient 实例(及其 HTTP 连接)的情况下清理套接字?
客户端日志如下所示:
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
MainClientExec - Target auth state: UNCHALLENGED
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:35 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="ApplicationRealm"[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 958[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=100[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: text/html;charset=utf-8[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
headers - http-outgoing-0 << HTTP/1.1 401 Unauthorized
headers - http-outgoing-0 << Date: Mon, 05 Oct 2015 13:30:35 GMT
headers - http-outgoing-0 << Server: Apache/2.2.12 (Linux/SUSE)
headers - http-outgoing-0 << Pragma: No-cache
headers - http-outgoing-0 << Cache-Control: no-cache
headers - http-outgoing-0 << Expires: Thu, 01 Jan 1970 01:00:00 CET
headers - http-outgoing-0 << WWW-Authenticate: Basic realm="ApplicationRealm"
headers - http-outgoing-0 << Content-Length: 958
headers - http-outgoing-0 << Keep-Alive: timeout=15, max=100
headers - http-outgoing-0 << Connection: Keep-Alive
headers - http-outgoing-0 << Content-Type: text/html;charset=utf-8
MainClientExec - Connection can be kept alive for 15000 MILLISECONDS
HttpAuthenticator - Authentication required
HttpAuthenticator - xyz:443 requested authentication
TargetAuthenticationStrategy - Authentication schemes in the order of preference: [Negotiate, Kerberos, NTLM, Digest, Basic]
TargetAuthenticationStrategy - Challenge for Negotiate authentication scheme not available
TargetAuthenticationStrategy - Challenge for Kerberos authentication scheme not available
TargetAuthenticationStrategy - Challenge for NTLM authentication scheme not available
TargetAuthenticationStrategy - Challenge for Digest authentication scheme not available
HttpAuthenticator - Selected authentication options: [BASIC [complete=true]]
wire - http-outgoing-0 << "<html><head><title>JBoss Web/7.0.13.Final - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>JBoss Web/7.0.13.Final</h3></body></html>"
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
MainClientExec - Target auth state: CHALLENGED
HttpAuthenticator - Generating response to an authentication challenge using basic scheme
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
headers - http-outgoing-0 >> Authorization: Basic dGN1YWRtaW46c3RhcnQ=
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS123 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "Authorization: Basic dGN1YWRtaW46c3RhcnQ=[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "HTTP/1.1 204 No Content[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:35 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 22[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=99[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: */*[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
headers - http-outgoing-0 << HTTP/1.1 204 No Content
headers - http-outgoing-0 << Date: Mon, 05 Oct 2015 13:30:35 GMT
headers - http-outgoing-0 << Server: Apache/2.2.12 (Linux/SUSE)
headers - http-outgoing-0 << Pragma: No-cache
headers - http-outgoing-0 << Cache-Control: no-cache
headers - http-outgoing-0 << Expires: Thu, 01 Jan 1970 01:00:00 CET
headers - http-outgoing-0 << Content-Length: 22
headers - http-outgoing-0 << Keep-Alive: timeout=15, max=99
headers - http-outgoing-0 << Connection: Keep-Alive
headers - http-outgoing-0 << Content-Type: */*
MainClientExec - Connection can be kept alive for 15000 MILLISECONDS
HttpAuthenticator - Authentication succeeded
TargetAuthenticationStrategy - Caching 'basic' auth scheme for https://xyz:443
PoolingHttpClientConnectionManager - Connection [id: 0][route: {s}->https://xyz:443] can be kept alive for 15.0 seconds
PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://xyz:443][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 20]
RequestAddCookies - CookieSpec selected: default
RequestAuthCache - Auth cache not set in the context
PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://xyz:443][total kept alive: 1; route allocated: 1 of 20; total allocated: 1 of 20]
PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {s}->https://xyz:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 20]
DefaultManagedHttpClientConnection - http-outgoing-0: set socket timeout to 90000
MainClientExec - Executing request DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1
MainClientExec - Target auth state: UNCHALLENGED
MainClientExec - Proxy auth state: UNCHALLENGED
headers - http-outgoing-0 >> DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1
headers - http-outgoing-0 >> Host: xyz
headers - http-outgoing-0 >> Connection: Keep-Alive
headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)
headers - http-outgoing-0 >> Accept-Encoding: gzip,deflate
wire - http-outgoing-0 >> "DELETE /prod/update-rest/private/deleteGroup/AS678 HTTP/1.1[\r][\n]"
wire - http-outgoing-0 >> "Host: xyz[\r][\n]"
wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.1 (Java/1.7.0_79)[\r][\n]"
wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
wire - http-outgoing-0 >> "[\r][\n]"
wire - http-outgoing-0 << "Group AS123 not found!"
wire - http-outgoing-0 << "HTTP/1.1 401 Unauthorized[\r][\n]"
wire - http-outgoing-0 << "Date: Mon, 05 Oct 2015 13:30:36 GMT[\r][\n]"
wire - http-outgoing-0 << "Server: Apache/2.2.12 (Linux/SUSE)[\r][\n]"
wire - http-outgoing-0 << "Pragma: No-cache[\r][\n]"
wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]"
wire - http-outgoing-0 << "Expires: Thu, 01 Jan 1970 01:00:00 CET[\r][\n]"
wire - http-outgoing-0 << "WWW-Authenticate: Basic realm="ApplicationRealm"[\r][\n]"
wire - http-outgoing-0 << "Content-Length: 958[\r][\n]"
wire - http-outgoing-0 << "Keep-Alive: timeout=15, max=98[\r][\n]"
wire - http-outgoing-0 << "Connection: Keep-Alive[\r][\n]"
wire - http-outgoing-0 << "Content-Type: text/html;charset=utf-8[\r][\n]"
wire - http-outgoing-0 << "[\r][\n]"
DefaultHttpResponseParser - Garbage in response: Group AS123 not found!HTTP/1.1 401 Unauthorized
DefaultHttpResponseParser - Garbage in response: Date: Mon, 05 Oct 2015 13:30:36 GMT
DefaultHttpResponseParser - Garbage in response: Server: Apache/2.2.12 (Linux/SUSE)
DefaultHttpResponseParser - Garbage in response: Pragma: No-cache
最佳答案
我设法解决了我的问题:
我创建了一个 HttpRequestExecutor 的子类来覆盖 canResponseHaveBody 方法,如下所示:
protected boolean canResponseHaveBody(final HttpRequest request,
final HttpResponse response) {
if ("HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) {
return false;
}
final int status = response.getStatusLine().getStatusCode();
return status >= HttpStatus.SC_OK
// && status != HttpStatus.SC_NO_CONTENT
&& status != HttpStatus.SC_NOT_MODIFIED
&& status != HttpStatus.SC_RESET_CONTENT;
}
在使用 HttpClients.custom().setRequestExecutor() 注册后,我能够通过 response.getEntity() 检索垃圾并使用它。
之后下一个请求就像魅力一样。
关于java - 让 HttpClient 在下一次请求之前消耗 "garbage",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32943192/
我有一个简单的 HATEOAS 使用 构建的提供程序 Spring 这为我提供了以下资源: { "_links" : { "self" : { "href" : "http:/
这里是 Clojure 初学者,不确定问题中的术语是否正确。 我正在使用 clj-webdriver 出租车 API 构建网络抓取工具。它需要从多个站点抓取数据。以下实际上不是项目中的代码,但我已经对
我使用pthread lib 2.8,操作系统内核是arm上的Linux 2.6.37。在我的程序中,线程 A 使用 pthread 接口(interface)将调度优先级设置为 sched_get_
我有一个大约 400MB 的二进制文件,我想将其转换为 CSV 格式。输出的 CSV 文件将约为 1GB(根据我的计算)。 我读取二进制文件并将其存储在一个结构数组中(其他处理也需要),当用户想要将其
我在编写我的专业应用程序时遇到一个串口线程问题。我有cpu消耗。当我在我的项目中添加 SerialCtrl.h(来自项目 SerialCtrl http://www.codeproject.com/A
总结:似乎 c 代码的 RAM 消耗取决于变量排序。有没有办法自动优化? 更长的版本:在这里,我粘贴了两个版本的代码,它们仅在变量排序方面有所不同。 版本 1: static unsigned lon
我有一个处理图像编辑(裁剪和调整大小)的 Windows 应用程序项目。不幸的是,这些图像处理会消耗大量内存和 CPU 资源(很容易达到 600MB 或 50% cpu),而且它只是裁剪和调整大小 2
我创建了一个实例化类 10 亿次的循环,并且非常惊讶地看到它在 0 毫秒内运行并且根据 Windows 任务管理器没有消耗 CPU 时间。 正如您从下面的代码中看到的那样,我显然没有对默认构造函数执行
我们有以下用户名验证规则: 用户名可以包含字母数字字符 用户名可以有下划线、连字符或句号 现在假设用户名是 ASCII 用户名不能以句点开头或结尾 用户名不能开始、结束或有任何空格 我们有以下相同的正
如何获取 C# 中所有进程的列表,然后获取每个进程的当前内存和 CPU 消耗? 非常感谢示例代码。 最佳答案 Process class有一个 GetProcesses 方法,可以让您枚举正在运行的进
如何从 linux 2.6.32 机器上的源代码中限制 C 程序的物理内存消耗? 我需要确定系统使用的页面替换算法的类型。 问题是,如果不限制一个进程在内存中可以拥有的页面数量,就很难分析页面错误的模
我正在编写一个 Linux 应用程序,它观察其他应用程序并跟踪资源消耗。我计划使用 Java,但编程语言对我来说并不重要。目标很重要,所以我可以切换到另一种技术或使用模块。我的应用程序将任何选定的第三
我有一个图标,旁边有一个复选框,包含在一个面板中。面板有悬停效果,点击面板时想选中框。 我想使用或阻止复选框的所有事件,仅以编程方式选择它。我希望该框在屏幕上显示为“已启用”,而“在幕后”几乎不起作用
我正在使用服务 REST,它当前有 5025 条记录,但当我使用该服务时,只出现 1,000 条记录。我可以做什么来完全消耗所有记录? 这是我的代码示例: $http({ method:
我已经搜索了几个小时但没有成功,是否可以跟踪 Blob 容器上 SAS 凭据的消耗情况? 我将向几个客户提供 SAS 凭证,并且我希望能够跟踪他们的 SAS 使用情况(操作次数、带宽使用情况...)
我创建了具有 1.75 GB RAM 的 B1 应用服务计划。我还创建了一个应用程序服务并向其部署了 docker 镜像。现在我停止了 docker 镜像,它的状态已停止,并且它是该应用程序服务计划中
与我们的合作伙伴一起为我们的客户(一家售后汽车零部件零售商)开发一个项目,他们利用 AR 和 VR 做了很多很酷的事情。我们的想法是使用 Hololens 并尝试帮助我们的客户在其大型仓库中进行物流操
这是一个简短的 Haskell 程序,可以生成 440 Hz 的声音。它使用pulseaudio作为音频后端。 import GHC.Float import Control.Arrow import
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 8 年前。 Improve this ques
tab.setOnCloseRequest(e -> { if (getEditorForTextArea(getSelectedTextArea()) != null
我是一名优秀的程序员,十分优秀!