我现在使用 WebClient 一段时间了。 (使用Mango SDK)
每次出现错误时,错误消息总是“Not Found”。该错误可能是由于登录问题、未找到服务器或页面造成的。任何错误代码 >= 400 都会导致具有相同消息但没有数据的相同异常。
我尝试使用WebRequest/WebResponse,但问题似乎总是相同。
我的意思是,我知道如何在 C# 中正确编写它(对于桌面),但在 windows 手机 上,我无法访问错误代码或响应正文。
我发现很多帖子都在谈论这个问题,但没有指出解决方案。
有没有人有解决方案或解决方法(即使是肮脏的......)我愿意接受任何建议。
I'm working with WebClient for some time now. (using the Mango SDK)
Each time I have an error, the error message is always "Not Found". Either the error is due to login problem, server or page not found. Any error code >= 400 cause the same Exception with the same message and no data.
I tried to use the WebRequest/WebResponse but it seems the problem is always the same.
I mean, I know how to write it correctly in C# (for desktop), but on windows phone, I have no way to access the error code nor the response body.
I found many posts talking about the problem, but no solutions are pointed.
Does anyone have a solution or a workaround (even a dirty one...) I'm open to any suggestion.
发布评论
评论(1)
该(非常具有误导性的)错误通常是由底层 HTTP 错误引起的。
如果您使用 HTTPS,可能是因为它是自签名的(或者 不受支持)证书。您可以通过将证书通过电子邮件发送到帐户来暂时解决此问题电话,但这不会在市场上流行。
如果请求不是 HTTPS,您可以运行 Fiddler 来找出根本错误是什么。 (专业提示:如果 Fiddler 在启动时正在运行,WP 模拟器将仅使用 Fiddler,因此您可能必须将其关闭)。
要访问数据,您需要获取
WebException
(它可能是抛出的InnerException
),然后您可以访问响应That (very misleading) error is often caused by an underlying HTTP error.
If you are using HTTPS, it could be because it's a self-signed (or otherwise unsupported) certificate. You can temporarily get around this by emailing the certificate to an account on the phone, but this won't fly in the marketplace.
If the requests aren't HTTPS, you can run Fiddler to find out what the underlying error is. (Pro tip: The WP emulator will only the use Fiddler if Fiddler was running when it started up so you may have to close it down).
To access the data, you need to get the
WebException
(it may be theInnerException
of what is being thrown) and then you can access the Response