简体   繁体   English

HttpClient 中的 GetStringAsync 方法在 WP8 中引发异常

[英]GetStringAsync method in HttpClient throw an exception in WP8

Recently, I develop an App for WP8 and at the begining all worked OK.最近,我为 WP8 开发了一个应用程序,一开始一切正常。 However, since yesterday nigth I was getting an error when trying to retrieve the RSS data from an url.但是,从昨天晚上开始,我在尝试从 url 检索RSS 数据时遇到错误。

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 .其中 source 是包含获取RSS 数据的 url 的字符串。 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 ().现在,它引发以下错误:响应状态代码不表示成功:404 ()。

If I put the url directly to any browser I can see the RSS feeds .如果我将 url 直接放入任何浏览器,我可以看到RSS 提要 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!问候!

You need provide access to internet for your WP emulator.您需要为您的 WP 模拟器提供互联网访问权限。

This article can be helpful这篇文章可能会有所帮助

connect WP emulator to internet 将 WP 模拟器连接到互联网

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.嗯...我也得到同样的错误...使用自己的类来调用 API,第一次调用导航成功,第二次调用使用按钮点击错误,两者都使用相同的代码。 On chrome rest client, the url success.在 chrome rest 客户端上,url 成功。

Did you try adding an user-agent header?您是否尝试添加用户代理标头? See DownloadString returns a 404 Error: Site needs a User-Agent Header .请参阅DownloadString 返回 404 错误:站点需要 User-Agent Header

Most webs blocks certain request to avoid robots.大多数网站会阻止某些请求以避免机器人。 Try it and tell me please...试试看,请告诉我...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM