Network errors on wp7

孤者浪人 提交于 2019-12-12 01:36:57

问题


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.

First, i'm trying HttpWebRequest

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

var response = (HttpWebResponse)await httpWebRequest.GetResponseAsync();

it throws an exception

The remote server returned an error: NotFound.

Then i tried HttpClient

Uri theUri = new Uri("https://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;
        } 

it returns

System.Net.HttpStatusCode.NotFound

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

  1. My current approach (via HttpWebRequest) definitely worked before
  2. I definitely have network access, because other network apps works more or less fine.
  3. BONUS: the same app on wp8 works fine. So server is perfectly available and request is valid.

EDIT1: 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: made a fresh wp7 project, added Bcl.Async and HttpClient. Still the same problem.

EDIT3: last night research:

on wp7 device this works ok:

        var client = new RestClient("http://example.com");
        var request = new RestRequest(String.Empty, Method.GET);

        client.GetAsync(request, (_response, _handle) =>
            {
                var resource = _response;
                var content = resource.Content;
            });

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


回答1:


Resetting to factory settings helped.



来源:https://stackoverflow.com/questions/23816912/network-errors-on-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!