[英]Android issue with HttpWebRequest/HttpClient
I have asp.net web service. 我有asp.net网络服务。 The web service has url like this: 网络服务有这样的网址:
mydomain dot com/service.asmx/getlocation?id=100
I always get below error. 我总是低于错误。 I tried both synchronous and async ways. 我尝试了同步和异步方式。 I even tried to use Google.com but I always get below error: 我甚至尝试使用Google.com,但我总是得到以下错误:
Unhandled Exception: 未处理的异常:
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
My code looks like this: 我的代码看起来像这样:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Timeout = 60000;
request.Method = "GET";
// I get error here
using (WebResponse response = request.GetResponse())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStream())
{
// Use this stream to build a JSON document object:
JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
// Return the JSON document:
return jsonDoc;
}
}
Thanks 谢谢
Edit : 编辑 :
I tried it on different emulators- Nexus 7 Lollipop(5.1.0) and Nexus S(4.4.2) 我尝试了不同的仿真器 - Nexus 7 Lollipop(5.1.0)和Nexus S(4.4.2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.