在 Java httpclient 中设置用户代理并允许重定向为 true
我正在尝试在 Java 中的 HttpClient apache 对象中设置我的用户代理字符串,但我不知道如何执行此操作。
请帮忙!
另外,我试图将重定向启用为 true,但也无法在 HttpClient 对象中找到此选项。
谢谢安迪
I am trying to set my user agent string in the HttpClient apache object in Java but I cannot find out how to do it.
Please help!
Also I am trying to enable redirects to true but also cannot find this option within the HttpClient object.
Thanks
Andy
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 HttpClient 4.0,以下内容对我有用:
HttpProtocolParams 驻留在 httpcore JAR 文件中: http:// /hc.apache.org/httpcomponents-core/download.html
With HttpClient 4.0, the following worked for me:
HttpProtocolParams resides in the httpcore JAR file: http://hc.apache.org/httpcomponents-core/download.html
使用 AndroidHttpClient,并将用户代理作为参数传递给 newInstance:
还有其他充分的理由使用 AndroidHttpClient 而不是原始 HttpClient。
Use AndroidHttpClient, and pass the user agent as a parameter to newInstance:
There are other good reasons to use AndroidHttpClient instead of the raw HttpClient as well.