gpt4 book ai didi

windows-phone-7 - HttpWebRequest 和 WebClient 在 Windows Phone 7 上返回 NotFound 但不是我正常的控制台应用程序

转载 作者:行者123 更新时间:2023-12-04 07:10:13 25 4
gpt4 key购买 nike

我正在尝试从此 URL https://valueboxtest.lb.dk/mobile/categories 下载常规 JSON 字符串从 Windows Phone 7 应用程序。

我尝试同时使用 WebClient 和 HttpWebRequest。他们都抛出异常

“The remote server returned an error: NotFound”

这是使用 WebClient 的代码
var webClient = new WebClient();
webClient.DownloadStringCompleted += (client_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("https://valueboxtest.lb.dk/mobile/categories"));

然后事件处理程序只显示内容,但 e.Result 抛出上述异常:
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null && !e.Cancelled) MessageBox.Show(e.Result);
}

对于 HttpWebRequest,我的代码如下所示:
var httpReq = (HttpWebRequest)WebRequest.Create(new Uri("https://valueboxtest.lb.dk/mobile/categories"));
httpReq.BeginGetResponse(HTTPWebRequestCallBack, httpReq);

使用以下回调:
private void HTTPWebRequestCallBack(IAsyncResult result)
{
var httpRequest = (HttpWebRequest)result.AsyncState;
var response = httpRequest.EndGetResponse(result);
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
this.Dispatcher.BeginInvoke(
new delegateUpdate(update),
new Object[] { reader.ReadToEnd() }
);
}

并使用委托(delegate)方法
delegate void delegateUpdate(string content);

private void update(string content)
{
MessageBox.Show(content);
}

在控制台应用程序中运行它

一切正常,返回的 JSON 字符串没有问题,我可以将结果打印到控制台。

不同的 URL 确实适用于 WP7

奇怪的是 URL http://mobiforge.com/rssfeed实际上在上述两种情况下都可以正常工作。

在模拟器和实际设备上都会出现此问题。

有什么问题? REST 服务是否以行为不端的方式返回数据?我真的希望你能帮助我!

注意:我没有同时运行 Fiddler2!

最佳答案

原因是该站点没有有效的证书。只需在 Mobile Internet Explorer 上尝试,您就会收到有关证书问题的提示。

How to ignore SSL certificates

移动设备在 SSL 证书方面更为严格。

如果您想将此应用程序放入生产环境,您需要为此服务器编写一个包装器(如果它不是您自己的),或者获取一个有效的证书。在短期内,为了测试,您可以将证书添加到您的设备中。

Here's a tool which might help you install a certificate.

关于windows-phone-7 - HttpWebRequest 和 WebClient 在 Windows Phone 7 上返回 NotFound 但不是我正常的控制台应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11032652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com