wp7上的网络错误

编程入门 行业动态 更新时间:2024-10-03 17:12:50
本文介绍了wp7上的网络错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试构建并运行几个月前在wp7上运行良好的旧应用程序,但是http客户端都没有为我工作。

I'm trying to build and run old application which worked fine several month ago on wp7, however none of http clients works for me.

首先,我m尝试 HttpWebRequest

var httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = HttpMethod.Get; httpWebRequest.Accept = "application/json"; var response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

它抛出异常

The remote server returned an error: NotFound.

然后我尝试 HttpClient

Uri theUri = new Uri("www.google.fi/"); HttpClient aClient = new HttpClient(); aClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); aClient.DefaultRequestHeaders.Host = theUri.Host; //Post the data HttpResponseMessage aResponse = await aClient.PostAsync(theUri, new StringContent(postData)); if (aResponse.IsSuccessStatusCode) { return aResponse.Content.ToString(); } else { // show the response status code return "HTTP Status: " + aResponse.StatusCode.ToString() + " - Reason: " + aResponse.ReasonPhrase; }

它返回

System.Net.HttpStatusCode.NotFound

看起来像手机不能到达网络...虽然:

Looking like phone cant reach network at all... Though:

  • 我当前的方法(通过HttpWebRequest)绝对有效
  • 我绝对有网络访问权限,因为其他网络应用程序或多或少都可以。
  • BONUS:wp8上的同一个应用程序运行正常。所以服务器完全可用,请求有效。
  • EDIT1: here here here / a>类似的问题,添加

    found here a similar issue, added

    client.Headers["Content-Type"] = "application/x-www-form-urlencoded"; client.Encoding = Encoding.UTF8;

    但仍然出现同样的错误。

    but still getting same error.

    EDIT2:制作了一个新的wp7项目,添加了Bcl.Async和HttpClient。仍然是同样的问题。

    made a fresh wp7 project, added Bcl.Async and HttpClient. Still the same problem.

    EDIT3:昨晚研究:

    last night research:

    在wp7设备上运行正常:

    on wp7 device this works ok:

    var client = new RestClient("example"); var request = new RestRequest(String.Empty, Method.GET); client.GetAsync(request, (_response, _handle) => { var resource = _response; var content = resource.Content; });

    但是当我切换到我的服务器时,它会在wp7设备上抛出NotFound异常。在wp8设备上,它返回正确的结果。

    But when i'm switching to my server, it throws NotFound exception on wp7 device. On wp8 device it returns correct result.

    推荐答案

    重置为出厂设置有帮助。

    Resetting to factory settings helped.

    更多推荐

    wp7上的网络错误

    本文发布于:2023-07-09 10:17:51,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1085590.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:错误   网络

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!