WinRT C# - HttpRequestException:错误 500 [英] WinRT C# - HttpRequestException: error 500

查看:27
本文介绍了WinRT C# - HttpRequestException:错误 500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 WP8 应用程序移植到 Windows 应用商店应用程序,并且在执行 HttpClient 的 getStringAsync 时收到 HttpRequestException.

I'm trying to port my WP8 application to a Windows Store App and I'm getting an HttpRequestException when performing the getStringAsync of the HttpClient.

这是给我问题的代码片段:

Here is the code snippet giving me the issue:

HttpClient client = new HttpClient();
            Stream stream = await client.GetStreamAsync(new Uri("http://www.psnapi.com.ar/ps3/api/psn.asmx/getPSNID?sPSNID=philippemexes", UriKind.Absolute));

这是完整的异常消息:

HttpRequestException:响应状态码不表示成功:500(内部服务器错误).我不得不说,指定的 URL 在浏览器中可以正常工作,并且完全相同的代码在 Windows Phone 项目中也可以正常工作.

HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error). I have to said that the indicated URL works in the browser and the exactly same code works properly in the Windows Phone project too.

有谁知道将所需的 xml 转换为字符串的可能解决方案以及为什么这适用于 Windows Phone 而不适用于 WinRT 应用程序?

Does anyone knows which could be a possible solution to get the desired xml to a string and why is this working for Windows Phone and not for a WinRT app?

非常感谢斯特凡诺

推荐答案

Fiddler 是你的朋友!

当请求标头中没有传递用户代理字符串时,服务似乎不太高兴被调用.尝试添加:

Appears that service isn't too happy about being called when there's not a user-agent string passed in the request headers. Try adding:

client.DefaultRequestHeaders.Add("user-agent", "blah blah blah");

在您的两行代码之间.blah blah blah 部分没有什么神奇之处:),它似乎适用于您的服务,但谁知道该服务对 UA 字符串的解释(如果有的话).

between your two lines of code. There's nothing magic in the blah blah blah part :), and it seems to work with your service, but who knows what, if any, interpretation the service is making of the UA string.

这篇关于WinRT C# - HttpRequestException:错误 500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆