HttpWebRequest and WebClient returning NotFound on Windows Phone 7 but not i normal console application
httpwebrequest, webclient, windows-phone-7
Solution
The reason is because that site does not have a valid certificate. Just try it on Mobile Internet Explorer and you'll get the prompt about an issue with the certificate.
How to ignore SSL certificates
Mobile devices are stricter when it comes to SSL certificates.
If you want to get this app into a production environment, you'll either need to write a wrapper for this server (if it's not your own), or get a valid certificate. In the short-term, for testing, you can add a certificate into your device.
Here's a tool which might help you install a certificate.
Problem
I'm trying to download a regular JSON string from this url https://valueboxtest.lb.dk/mobile/categories from a Windows Phone 7 Application. I have tried to both use WebClient and HttpWebRequest. They both throw an exception ``` “The remote server returned an error: NotFound” ``` This is the code for using the WebClient ``` var webClient = new WebClient(); webClient.DownloadStringCompleted += (client_DownloadStringCompleted); webClient.DownloadStringAsync(new Uri("https://valueboxtest.lb.dk/mobile/categories")); ``` The eventhandler then just show the content, but e.Result throws the above mentioned exception: ``` void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null && !e.Cancelled) MessageBox.Show(e.Result); } ``` For the HttpWebRequest my code looks as follows: ``` var httpReq = (HttpWebRequest)WebRequest.Create(new Uri("https://valueboxtest.lb.dk/mobile/categories")); httpReq.BeginGetResponse(HTTPWebRequestCallBack, httpReq); ``` With the following callback: ``` 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() } ); } ``` And with the delegate method ``` delegate void delegateUpdate(string content); private void update(string content) { MessageBox.Show(content); } ``` Running it in a console application Everything works just fine and the JSON string is returned with no problems and I am able to print the result to the console. Different URL does work on WP7 The weird thing is that the URL http://mobiforge.com/rssfeed actually works fine in both of the above mentioned scenarios. This issue occurs both in the Emulator and on an actual device. What could be wrong? Is the REST service returning the data in misbehaving way? I really hope you can help me! Note: I'm not running Fiddler2 at the same time!