GetStringAsync method in HttpClient throw an exception in WP8

▼魔方 西西 提交于 2019-12-11 03:57:25

问题


Recently, I develop an App for WP8 and at the begining all worked OK. However, since yesterday nigth I was getting an error when trying to retrieve the RSS data from an url.

This is part of the code I use to get the data:

try
{
   HttpClient client = new HttpClient();
   var result = await client.GetStringAsync("http://www.scoop.it/t/recycling-by-miguel18/rss.xml");
   var parseResult = XDocument.Parse(result);
   . . .
}
catch (Exception ex)
{
   throw new Exception("Error: " + ex.Message);
}

Where source is the string which contain the url to get the RSS data. As commented, at the begining it was working OK, I was able to get the data in work with it.

Now, it raise the following error: Response status code does not indicate success: 404 ().

If I put the url directly to any browser I can see the RSS feeds. So, I don't undertand what would be wrong with the code. I am a little lost.

If you can help me to figure out what is wrong that would be very helpful

Regards!


回答1:


You need provide access to internet for your WP emulator.

This article can be helpful

connect WP emulator to internet




回答2:


hmm... I also get same error... using own class to call API, first call on navigatedTo success, second call using button click error, both using same code. On chrome rest client, the url success.




回答3:


Did you try adding an user-agent header? See DownloadString returns a 404 Error: Site needs a User-Agent Header.

Most webs blocks certain request to avoid robots. Try it and tell me please...



来源:https://stackoverflow.com/questions/18432133/getstringasync-method-in-httpclient-throw-an-exception-in-wp8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!