问题标签 [apache-httpclient-4.x]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 如何使用 Jackson 注释从 HttpResponse 反序列化 JSON 对象?
我正在使用 Apache http 类调用在响应正文中返回 JSON 对象的 Web 服务。我有一个映射到 JSON 对象的带有 Jackson 注释的 java 类。我想做这件事,但谷歌没有找到正确的样板。
java - Apache HttpClient 4.1 - 代理身份验证
在使用 Apaches HttpComponent 的 httpclient 时,我一直在尝试从配置的属性中配置代理身份验证的用户和密码,但没有成功。我发现的所有示例都指的是不再可用的方法和类,例如HttpState
和setProxyCredentials
。
那么,谁能给我一个如何配置代理凭据的示例?
java - 查询 ThreadSafeClientConnManager (Apache HttpClient 4.1.1)
我正在为我的连接池使用 ThreadSafeClientConnManager Apache HttpComponenets-Client4.1.1。
当我将连接释放回池时,我说:
cm.releaseConnection(client,-1,TimeUnit.SECONDS); cm.closeExpiredConnections(); cm.closeIdleConnections(20, TimeUnit.SECONDS);
[这里 cm 是 ThreadSafeClientConnManager 的对象] 并且如 javadoc releaseConnection(ManagedClientConnection conn, long validDuration,TimeUnit timeUnit) 中所述,将有效持续时间设置为 -ve (<=0) 值。
但是当我看到服务器日志时,我发现:
org.apache.http.impl.conn.DefaultClientConnection] 连接关闭 2011-08-17 14:12:48.992 DEBUG Other Thread-257 org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager 释放的连接不可重用。2011-08-17 14:12:48.992 调试其他线程 257 org.apache.http.impl.conn.tsccm.ConnPoolByRoute 释放连接 [HttpRoute[{}->http://server-name:port][null] 2011-08-17 14:12:48.992 调试其他线程 257 [org.apache.http.impl.conn.tsccm.ConnPoolByRoute] 通知没有人,没有等待线程 2011-08-17 14:12:48.993调试其他线程 257 [org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager] 关闭过期连接 2011-08-17 14:12:48.993 调试其他线程 257 [shaded.org.apache.http.impl.conn .tsccm.ConnPoolByRoute] 关闭过期连接 2011-08-17 14:12:48。
在这里,我在日志中看到“已释放的连接不可重用”这是否意味着“-1”没有使连接可重用并且连接已关闭而不是返回池?如果可以,任何人都可以建议我如何使其可重复使用。
提前致谢。
java - 如何将日期标头添加到 httpGet
我目前正在使用 HttpGet(apache) 方法向 Web 服务发出请求。当我调用服务器时,它给了我这个错误:
“请求时间和服务器时间之间的差异太大” 然后我知道服务器需要在 GMT 中有请求,所以我相应地添加了一个标头(addHeader)来做同样的事情。但我仍然有同样的问题。
有什么想法/想法吗?
一些代码:
java - 当 EntityUtils.toString() 返回异常时,有没有办法获取 HttpEntity 的字符串值?
我一直遇到这种情况,我得到一个错误的 HTTP 响应(如 400),但无法查看 HttpResponse 对象中的 HttpEntity。当我使用调试器单步执行时,我可以看到实体有内容(长度 > 0),我什至可以查看内容,但我看到的只是一个数字数组(我猜是 ASCII 码?)有帮助。我将在实体上调用 EntityUtils.toString(),但我得到一个异常——要么是 IOException,要么是某种“对象处于无效状态”异常。这真是令人沮丧!有没有办法以人类可读的形式获取这些内容?
这是我的代码:
看看我在哪里抛出异常?我想做的是吸出 HttpEntity 的内容并将其放入异常中。
java - 如何使用 HttpComponents 发布数组参数
我想用 Apache http-components (4.1.2) 执行这个命令
目标 api 需要字符串和string-keys参数作为数组,这意味着对每个参数重复strings[]和string-keys[]。
此 curl 命令工作正常,但使用 Http 组件,而我得到完全相同的参数。
也许我做错了什么。
POST 参数看起来像:
如果我将它们放在 curl 中的 --data 后面,它可以工作,但不能与 HttpCoponents 一起使用。有人可以解释我为什么吗?
提前致谢
java - Apache HttpGet url 编码问题(加号、+)
我正在使用 HttpClient 发送 GET 请求,+
但未编码。
1.如果我像这样传递query
未编码的参数字符串
然后+
符号不被编码,它在服务器上作为空格接收。url 的其余部分编码良好。
query
2.如果我像这样对字符串中的参数进行编码
然后我在服务器上得到一堆奇怪的符号,可能是因为url被编码了两次。
3.如果我只+
用%B2
这样替换
然后%B2
在 HttpClient 执行 GET 时进行编码
如何使用 Apache HttpClient 正确编码 Get 参数并确保+
也已编码?
java - Google Map Api 总是使用 HttpClient 返回 request_denied
为什么上面的代码总是给我这个错误
“html_attributions”:[],“结果”:[],“状态”:“REQUEST_DENIED”]
我也试过这个逻辑
基本上我只是想从 GMapI 中获取一些结果。在我看来,它没有使用 URL 设置参数也让我知道如何打印当时正在执行的完整 url。
java - Java HttpClient emulating IE8 behaviour
Im using Apache HttpClient from HttpComponents projects. I have added custom trust and key managers to it to handle two-way authentication (my trust manager accepts everything and my key manager sends always the same client certificate).
I send two following requests:
1. Get /resource.html (this one redirects to sth.dll using http-equiv="Refresh" meta tag)
2. Get /scripts/sth.dll
I do this to emulate IE8 behaviour which was use to connect to sth.dll service (and it works).
If I ty to connect to sth.dll service directly (either using browser or httpclient)
I get 500 error: cannot find the path specified. Unfortunately I still get 500 error when I use the above method with manual redirec
My question is what else I need to emulate to get this service working?
Is it possible that the problem lies in the fact that IE reuses data from handshake done in 1 request and my httpclient do two handshakes? If yes then how to force httpclient to reuse ssl informaton
I do not have access to server and the possibility to ask service providers for help (because they only support access through ie8). The server is IIS/6.0. There are no visible cookies (I used Fiddler to get info on traffic from IE8).
Can anybody give me some new idea on where to look ?
java - 应该不鼓励使用 java.net.HttpURLConnection ,因为 org.apache.http.client.HttpClient 更好吗?
我仍然看到人们使用 HttpURLConnection 与网站进行通信。这个论坛也有很多与 HttpURLConnection 相关的问题。现在,来自 apache 的 HttpClient 几乎可以实现 HttpURLConnection 可以实现的所有功能,而且代码更少、更干净、更高效。我的问题是,
- 作为开发人员,我们应该不鼓励使用 HttpURLConnection 吗?
- 是否有任何用例,其中 HttpURLConnection 的使用应该优于 HttpClient ?