WebException on an HTC Windows Phone 7

December 9 2010

So, had this issue where HTTPWebRequest was throwing a WebException on a production HTC HD7 device – the error was "The remote server returned an error: NotFound."  However, the browser itself worked fine. What was really weird was that these same HTTPWebRequest calls work fine in the emulator and Samsung devices. I was totally flummoxed.

Turns out that there were a few misleading things to solve this bug.

First, was that all Web Request errors are mapped to a 404. So the real error could be (and was) different. In fact, the error from the server was a 500. The reason? The call to the server was the start of an OAuth handshake which involved sending a timestamp. Apparently, HTC phones with no SIM card don’t set the date or time correctly, and thus the DateTime.UtcNow was returning something totally bogus, and the server was rejecting the call.

The fix was to add a dialog to the app in the event that the time hasn’t been properly set.

One suggestion for debugging these types of HTTP failures is by setting the WiFi proxy on the phone to your machine’s IP, then using Fiddler2, and enabling the “Remote connections” option under Fiddler’s options.

Comments (3) -

12/11/2010 10:29:16 AM #

leovernazza

mmmh.. interesting...

I guess that's why I can't use any Twitter app with my Samsung Focus as well. Seesmic, Twitter for Windows Phone, etc. None of them handle this properly.

leovernazza

12/13/2010 7:13:28 AM #

irhetoric

Well, if you set the time you should be okay.

irhetoric

12/13/2010 7:49:37 AM #

leovernazza

No, setting the date doesn't make the trick.

It's obviously not the same problem, but I guess the phones weren't tested enough without SIM cards.

leovernazza

Add comment

Enter your name, handle, alias, or email.

We'll incarnate your avatar from the services below.



biuquote
Loading