【发布时间】:2014-02-26 17:11:20
【问题描述】:
我有以下代码。异步调用从不返回任何内容。即使是 google.com。
try
{
using (
var client = new HttpClient()) {
var response = client.GetAsync("http://www.google.com");
Debug.WriteLine("Coming here1"+response.Result.IsSuccessStatusCode);
if (response.Result.IsSuccessStatusCode)
{
// by calling .Result you are performing a synchronous call
Debug.WriteLine("Coming here1");
var responseContent = response.Result.Content;
// by calling .Result you are synchronously reading the result
string responseString = responseContent.ReadAsStringAsync().Result;
//Console.WriteLine(responseString);
}
else { Debug.WriteLine("else"); }
}
}
catch(Exception e)
{
Debug.WriteLine(e.ToString());
}
}
【问题讨论】:
-
您没有使用 WebClient 是否有特定原因?
-
没有具体原因。我听说 httpclient 是新的改进了...我读了这个stackoverflow.com/questions/14435520/… 并关注了
标签: windows-phone-8