2014-06-09 455 views
7

我正在使用.net框架3.5开发手机应用程序,该应用程序使用API​​服务调用来检查来自website.I的电子邮件地址。现在用下面的代码来执行,命名空间'System.Net'中不存在类型或名称空间名称'Http'

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”。

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

由于

+0

@Steve:为什么? HttpClient在System.Net.Http命名空间中:http://msdn.microsoft.com/en-gb/library/system.net.http.httpclient.aspx –

+0

不适用于.NET 3.5。命名空间根本不可用3.5 –

+0

@JonSkeet确实太快了,用LinqPAD中的Intellisense看,错过了参考并跳到了错误的结论 – Steve

回答

7

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

HttpClient使用像TPL这样的功能仅在.NET 4 +中可用。您需要使用System.Net.WebClientWebRequest。如果您收到任何编译错误,请确保您已添加适当的using声明。这两个类自.NET 1.1起可用,位于System.dll库中,因此始终可用。

+0

我可以知道什么是.net 3.5中的HttpClient的替代品。我是新来的学习.net你能告诉我如何解决我的问题。 – user3100575

+0

检查编辑。您已经使用了正确的类型,但忘记使用正确的名称空间。检查文档,它们包含一个简单但完整的示例。 –

+0

.net框架3.5在WebClient上有支持。 – user3100575

相关问题