Windows phone 8 Windows phone httpclient不工作

Windows phone 8 Windows phone httpclient不工作,windows-phone-8,Windows Phone 8,我有以下代码。异步调用从不返回任何内容。即使是谷歌 try { using ( var client = new HttpClient()) { var response = client.GetAsync("http://www.google.com"); Debug.WriteLine("Coming here1"+response

我有以下代码。异步调用从不返回任何内容。即使是谷歌

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());
            }
        }
试试这个

try{
     WebClient wc = new WebClient();
     wc.DownloadStringCompleted+= (sender,args) => {
        Debug.WriteLine(args.results);
     };
     wc.DownloadStringAsync(new Uri(@"http://www.Google.com",UriKind.RelativeOrAbsolute));

}
catch(Exception e){ Debug.WriteLine(e.Message); }

您似乎没有等待异步调用

尝试更改
var response=client.GetAsync(“http://www.google.com");
to
var response=wait client.GetAsync(“http://www.google.com");

记住将您的方法标记为
async

您还阻止了异步调用
ReadAsStringAsync()。结果
。与client.GetAsync一样,确保等待调用,而不是使用
Result
阻塞。这说明了这个话题


读一读异步/等待。一旦你掌握了窍门,你就会爱上它。

你不使用WebClient有什么具体原因吗?没有具体原因。我听说httpclient是一个有改进的新客户机…我读了这篇文章,并进行了跟踪。如果您在电话中遇到任何关于如何使用Httpclient的教程,请告诉我,但我已经找到了Httpclient选项。以下是工作代码
code
String stresult=wait signUpReq.GetStringAsync(finalUri)<代码>代码