3

我正在尝试通过 hbc-twitter4j-v3 获取推文。示例代码是:https ://github.com/twitter/hbc/blob/master/hbc-example/src/main/java/com/twitter/hbc/example/Twitter4jSampleStreamExample.java 为了在代理上启用身份验证,我也有设置主机、端口和身份验证的系统属性。但它显示以下错误 -

[main] INFO com.twitter.hbc.httpclient.BasicClient - 执行的新连接:hosebird-client-0,端点:/1.1/statuses/sample.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase-hosebird-client-0 建立连接
[main] INFO com.twitter.hbc.httpclient.BasicClient - 停止客户端:hosebird-client-0,端点:/1.1/statuses/sample.json?delimited=length&stall_warnings=true
[main] INFO com.twitter.hbc.httpclient.ClientBase - 软管鸟客户端 0 退出事件 - 被用户停止:等待 5000 毫秒
[main] WARN com.twitter.hbc.httpclient.ClientBase-hosebird-client-0 客户端线程未能在 5000 毫秒内完成
[main] INFO com.twitter.hbc.httpclient.BasicClient - 成功停止客户端:hosebird-client-0,端点:/1.1/statuses/sample.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] 警告 com.twitter.hbc.httpclient.ClientBase-hosebird-client-0 未知主机-stream.twitter.com
[hosebird-client-io-thread-0] 警告 com.twitter.hbc.httpclient.ClientBase-hosebird-client-0 无法正确建立连接
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase -hosebird-client-0 完成处理,准备关闭连接
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase-hosebird-client-0 关闭 httpclient 连接管理器

有什么帮助吗??提前致谢

4

1 回答 1

1

希望我没有忽略某些东西,但这就是我的感觉...

如果通过设置属性是指http.proxy*那些属性,我认为它不会起作用,因为软管鸟客户端在引擎盖下使用 Apache 的 HTTP 客户端,它似乎没有使用它们。

粗略看一下代码,特别是在ClientBuilder.

看起来您可以HttpClient使用代理的一种方法是将其添加到HttpParams对象中,例如:

HttpParams params = ...
HttpHost proxy = new HttpHost(hostname, port);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

虽然该HttpParams对象没有暴露在您可能扩展的任何地方ClientBuilder以提供您的代理配置。如果您查看该ClientBuilder#build()方法,您可以看到HttpParams设置对象的位置。祝你好运!

编辑:此外,此问题表明没有计划直接在 hbc 中添加代理支持。

于 2013-09-13T16:11:36.483 回答