我想通过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 - New connection executed: hosebird-client-0, endpoint: /1.1/statuses/sample.json?delimited=length&stall_warnings=true [hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 Establishing a connection [main] INFO com.twitter.hbc.httpclient.BasicClient - Stopping the client: hosebird-client-0, endpoint: /1.1/statuses/sample.json?delimited=length&stall_warnings=true [main] INFO com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 exit event - Stopped by user: waiting for 5000 ms [main] WARN com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 Client thread failed to finish in 5000 millis [main] INFO com.twitter.hbc.httpclient.BasicClient - Successfully stopped the client: hosebird-client-0, endpoint: /1.1/statuses/sample.json?delimited=length&stall_warnings=true [hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 Unknown host - stream.twitter.com [hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 failed to establish connection properly [hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 Done processing, preparing to close connection [hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hosebird-client-0 Shutting down httpclient connection manager
任何帮助? 提前致谢
答案 0 :(得分:0)
希望我没有忽视某些东西,但这就是它在我看来......
如果通过设置属性意味着http.proxy*
属性,我认为它不会起作用,因为hosebird-client使用Apache的HTTP客户端,它似乎没有使用它们。
从粗略地看一下代码,特别是ClientBuilder
周围,它看起来不像hbc支持代理配置 - 也许他们有充分的理由不要或者根本不需要这个功能,也许尝试请求吗?
看起来HttpClient
使用代理的方法之一是adding it to the HttpParams
object,例如:
HttpParams params = ...
HttpHost proxy = new HttpHost(hostname, port);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
虽然HttpParams
对象未在任何地方公开,但您可能会扩展ClientBuilder
以提供代理配置。如果查看ClientBuilder#build()
方法,可以看到HttpParams
对象的设置位置。祝你好运!
编辑:此外,此issue表示没有计划直接在hbc中添加代理支持。