无法在WebClient对象中查找UploadStringTaskAsync方法

时间:2013-09-10 19:28:28

标签: c# .net visual-studio-2012 windows-phone-8

我试图在UploadStringAsync()(属于System.Net.WebClient)调用上使用等待,所以我读了我需要使用方法UploadStringTaskAsync()代替,但VisualStudio 2012表示该方法未在WebClient类上定义,我该如何解决?有没有人面临同样的问题? 感谢

2 个答案:

答案 0 :(得分:2)

安装Microsoft.Bcl.Async NuGet package

更好的是,使用新的HttpClient package代替WebClient;它更加async - 友好。

答案 1 :(得分:0)

Windows Phone 8中的

WebClient 未定义 UploadStringTaskAsync ,它具有 webClient.UploadStringAsync(),您可以使用和处理

void sendWebRequest()
     {
         WebClient webClient = new WebClient();
         String data = "";//data to upload
         String url="";
         webClient.UploadStringCompleted += webClient_UploadStringCompleted;
         webClient.UploadStringAsync(new Uri(url), data);
     }
     void webClient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
     { }