windows-phone-7 – HttpWebRequest和WebClient在Windows Phone
我正在尝试从
Windows Phone 7应用程序从此URL
https://valueboxtest.lb.dk/mobile/categories下载常规JSON字符串.
我曾尝试过使用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")); 然后,eventhandler只显示内容,但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 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. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 无法投射COM对象 – Microsoft Outlook和C#
- windows-8 – Moto X没有出现在Eclipse Windows 8.1中
- Windows使用VNC连接linux桌面
- windows-server-2008 – 混合网络2003/2008文件共享问题
- windows-server-2012-r2 – 如何在Windows 2012中禁用RC4?
- 在Windows x64上使用RtlAddFunctionTable描述动态生成的代码
- windows – _EPROCESS对象和_KPROCESS对象有什么区别
- windows-7 – Windows 7版Virtual PC中“关闭”和“关闭”有
- windows-server-2003 – Windows Defrag实用程序是否在RAID
- windows-server-2008-r2 – 3个域控制器的一个SSL证书