0

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: 
4

1 回答 1

5

这是有趣的部分 - NotFound 是一个非常通用的错误,它可以告诉您请求内部失败或 Web 服务拒绝了您的请求。

为了更好地了解正在发生的事情,请将其包装在try/catch块中(对于 a WebException)并阅读响应:

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());
    }
}

报告结果,我将能够为您提供更多帮助。

于 2013-02-14T05:39:49.073 回答