类型或命名空间名称' Http'名称空间中不存在System.Net'

时间:2014-06-09 12:41:09

标签: c# .net wpf visual-studio

我正在开发.net framework 3.5中的手机应用程序,该应用程序正在使用API​​服务调用来检查来自网站的电子邮件地址。我正在使用以下代码执行该操作,

using System.Net.Http;

HttpClient webClient = new HttpClient();
webClient.QueryString.Add("email", email);
Stream stream = webClient.OpenRead(brandEndPoint);

最初我使用WebClient代替HttpClient,我收到此错误“The type or namespace name 'WebClient' could not be found”谷歌并使用HttpClient修复此问题。

WebClient替换为HttpClient后,我收到此错误“The type or namespace name 'Http' does not exist in the namespace 'System.Net”。

需要帮助来解决这个问题。

由于

1 个答案:

答案 0 :(得分:7)

HttpClient在.NET 4.5或4.0中可用Microsoft.Net.Http NuGet包。它根本不适用于.NET 3.5。

HttpClient使用仅在.NET 4 +中提供的TPL等功能。

您必须使用System.Net.WebClientWebRequest。如果您收到任何编译错误,请确保已添加正确的using语句。自.NET 1.1以来,这两个类在System.dll库中可用,因此始终可用。

相关问题