简体   繁体   English

Windows Phone WebClient无法正常工作

[英]windows phone WebClient doesn't work

WebClient client = new WebClient();

When I try do to something like that I get an error 当我尝试做类似的事情时,我得到一个错误

Error 2 The type or namespace name 'WebClient' does not exist in the namespace 'System.Net' (are you missing an assembly reference?) 错误2类型或名称空间名称'WebClient'在名称空间'System.Net'中不存在(您是否缺少程序集引用?)

What's wrong? 怎么了?

It is available in WP8 Silverlight projects. 在WP8 Silverlight项目中可用。 I prefer to use Windows.Web.Http.HttpClient instead. 我更喜欢使用Windows.Web.Http.HttpClient

public async Task<String> myFunction(){
    HttpClient httpClient = new HttpClient();
    String response = await httpClient.GetStringAsync(
        new Uri("http://www.example.com")
    );
    return response;
}

To use the function you will again use await. 要使用该功能,您将再次使用await。

String data= await myFunction()

and so on... 等等...

You might need to install Microsoft HTTP Client Libraries from nuget 您可能需要从nuget安装Microsoft HTTP客户端库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM