HttpUrlConnection 重定向不使用原始连接的请求属性
则设置连接属性不会延续到重定向连接
HttpURLConnection mConnection = (HttpURLConnection) url.openConnection();
mConnection = addRequestProperty("User-Agent", "Mozilla");
InputStream stream = mConnection.getInputStream();
如果存在 302 代码、mConnection
已重定向,但用户代理为 “Java/1.5.0_28”
, 。
有什么建议如何处理这个问题吗?
Setting properties of a connection do not carry forward to redirected connections
HttpURLConnection mConnection = (HttpURLConnection) url.openConnection();
mConnection = addRequestProperty("User-Agent", "Mozilla");
InputStream stream = mConnection.getInputStream();
if there is a 302 code, mConnection
is redirected, but the user-agent is "Java/1.5.0_28"
.
Any suggestion how to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有改变,一开始就是这样。
addRequestProperty()
不会覆盖默认值。请改用setRequestProperty()
。It didn't change, it started out that way.
addRequestProperty()
won't override the default. UsesetRequestProperty()
instead.