【问题标题】:Httpwebrequest fails with Not Found error : windows phone 8Httpwebrequest 失败并出现 Not Found 错误:windows phone 8
【发布时间】:2023-03-21 02:40:01
【问题描述】:

我正在尝试从 windows phone 8 将 httpwebrequest 发布到 Rest 服务,http 标头为:User-agent =@"Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0;Trident/6.0; IEMobile/10.0 ;ARM;触控;微软;虚拟)" 以及帖子正文:payload=testvalue&item1=value;

从 REST 客户端发布时,相同的请求会返回响应

以下是windows phone 8代码中发生的异常

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: 

【问题讨论】:

  • 确保您在帖子中使用流复制而不是流 -> unicode 字符串 -> 流

标签: .net windows-phone-7 c#-4.0 windows-phone-8


【解决方案1】:

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

为了更好地了解正在发生的事情,请将其包装在 try/catch 块中(对于 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());
    }
}

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

【讨论】:

  • Hi Den 下面是异常的详细信息,希望你能得到一些关于这个问题的信息,System.Net.WebException 被捕获 HResult=-2146233079 Message=远程服务器返回错误:未找到。 Source=System.Windows InnerException: System.Net.WebException HResult=-2146233079 Message=远程服务器返回错误:NotFound。 Source=System.Windows InnerException:
  • 这不是问题——你给了我异常细节。检查我编辑的答案,看看我的意思。
  • 您好,来自异常的响应详细信息,我能够解决问题谢谢
猜你喜欢
  • 2016-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-11
  • 2023-01-09
  • 1970-01-01
  • 2021-02-21
  • 1970-01-01
相关资源
最近更新 更多