开发者

Avoid mobile website redirection when trying to get an XML feed on Android

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜