尝试在 Android 上获取 XML feed 时避免移动网站重定向
我正在尝试从网站获取 xml feed,没什么特别的。 我的问题是,当我尝试从 Android 应用程序获取提要时,我会自动重定向到主页的移动版本网站。这意味着我获得的提要是移动网站的 HTML 页面,而不是预期的 xml 文件。
我尝试以这种方式打开提要:
URL feedUrl = new URL(address);
Inputstream iStream = feedURL.openStream();
//or
Inputstream iStream = (InputStream)feedURL.getContent();
所以...还有其他方法吗?无论如何要避免这种重定向?我完全无法控制该网站...
谢谢大家!
I'm trying to get an xml feed from a website, nothing really special.
My problem is, when I'm trying to get my feed from my Android application, I'm automatically redirected to the mobile version of the website at the home page. This mean that the feed I get is the HTML page of the mobile website, not the xml file expected.
I tried to open the feed this way :
URL feedUrl = new URL(address);
Inputstream iStream = feedURL.openStream();
//or
Inputstream iStream = (InputStream)feedURL.getContent();
So... Is there anyway other way to do it? Anyway to avoid this redirection? I have absolutely no control over the website...
Thanks everyone!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能发生的情况是 URL 连接将默认的 用户代理 标头附加到 HTTP 请求。移动网站收到此信息并将您重定向到移动网站。我相信使用 Android 版本的 URL< 来改变这种行为是不可能的。 /a> 类。
解决方案是使用 HttpClient,它无论如何你应该已经这么做了。
What is probably happening is that the URL connection attaches a default user agent header to the HTTP request. The mobile web site receives this and redirects you to the mobile web site. I believe that it won't be possible to change this behaviour with Android's version of URL class.
A solution would be to use HttpClient, which you should be doing already anyhow.