0
votes

i am trying to post a httpwebrequest to a Rest service from windows phone 8 , with the http headers :User-agent =@"Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0; ARM; Touch; Microsoft; Virtual)" And the post post body :payload=testvalue&item1=value;

the same request does returns a response when posted from a REST client

and below is the exception occured in windows phone 8 code

System.Net.WebException was caught
HResult=-2146233079
Message=The remote server returned an error: NotFound.
Source=System.Windows
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: NotFound.
Source=System.Windows
InnerException: 
1
Make sure you're using a stream copy on post rather than stream -> unicode string -> stream - user2009677

1 Answers

5
votes

Here is the interesting part - NotFound is a very generic error, that can tell you that either the request failed internally or the web service rejected your request.

To get a better idea of what is going on, wrap it in a try/catch block (for a WebException) and read the response:

try
{
    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(respResult);
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        Debug.WriteLine(reader.ReadToEnd());
    }
}
catch (WebException ex)
{
    using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
    {
        Debug.WriteLine(reader.ReadToEnd());
    }
}

Report back with results and I will be able to help you more.