我正在尝试使用免费的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?