我正在尝试使用以下代码查看http://simpledesktops.com/browse/desktops/2012/may/17/where-the-wild-things-are/的来源:
String URL = "http://simpledesktops.com/browse/desktops/2012/may/17/where-the-wild-things-are/";
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
webClient.Encoding = Encoding.GetEncoding("Windows-1255");
string download = webClient.DownloadString(URL);
webClient.Dispose();
Console.WriteLine(download);
当我运行它时,控制台返回一堆看起来像是被错误解码的废话。
我也尝试添加标题但无济于事:
webClient.Headers.Add("user-agent", "Mozilla/5.0 (Windows; Windows NT 5.1; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4");
webClient.Headers.Add("Accept-Encoding", "gzip,deflate");
其他网站都返回了正确的 html 源代码。我还可以通过 Chrome 查看页面的源代码。这里发生了什么?