我刮的时候缺少`System.Net.Http'错误

时间:2017-10-01 13:55:44

标签: c#

我正在尝试使用免费的https://repl.it/languages/csharp编译器来抓取纽约时报

using System;
using System.Net.Http;
using System.Threading.Tasks;

class DownloadPageHttpClient
{
 static void Main()
 {
    Task t = new Task(DownloadPageAsync);
    t.Start();
    Console.WriteLine("Downloading page...");
    Console.ReadLine();
}

static async void DownloadPageAsync()
{
    string page = "http://www.nytimes.com";

    using (HttpClient client = new HttpClient())
    using (HttpResponseMessage response = await client.GetAsync(page))
    using (HttpContent content = response.Content)
    {
        string result = await content.ReadAsStringAsync();

        Console.WriteLine(result);
    }
  }
}

我几乎可以肯定我的代码是正确的,并且我已经包含了使用System.Net.Http,但我仍然收到此错误消息:

main.cs(2,14): error CS0234: The type or namespace name `Http' does not    exist in the namespace `System.Net'. Are you missing `System.Net.Http' assembly reference?

1 个答案:

答案 0 :(得分:0)

这是因为您使用的在线编译器没有该库。

使用http://rextester.com/即可。