How do I get HTTP StatusCodes other than 200 on Windows Phone 7?
Currently with Windows Phone 7 if I access a page that returns a StatusCode of 500 or something besides 200 OK I get a message saying the NotFound. In silverlight there are a couple options for handling this:
- Use SilverlightFaultBehavior if you control the REST Service (I don't though)
- Use
HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
I'm wondering开发者_运维问答 if there are any options like this for the Windows Phone 7.
All you have to do is catch the WebException
, and access the response within that. Then you can get at the status code, response stream etc.
If that's no use to you, please post the code you're using and what you're trying to do - it's hard to know exactly what you've tried at the moment.
HttpWebResponse includes a StatusCode property. Can't you use that?
webResponse = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);
webResponse.StatusCode;
精彩评论