wp7上的网络错误 [英] Network errors on 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("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;
}
它返回
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("http://example.com");
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上的网络错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!