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

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

问题描述

我正在尝试将WP8应用程序移植到Windows Store应用程序,并且在执行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?

非常感谢
Stefano

Thank you very much Stefano

推荐答案

提琴手是您的朋友!

似乎没有传递用户代理字符串时,该服务对于调用该服务不太满意请求标头。尝试添加:

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");

等等等等部分并没有什么魔力:),它似乎可以与您的服务一起使用,但是谁知道(如果有的话)该服务正在解释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天全站免登陆