-2
我有这个功能来下载网站的html代码,但是当我输入这个特定的网站时,它返回一个点(。)而不是html代码,任何人都可以告诉我什么是错或为什么是它不会重新调整代码?Webclient下载字符串返回意外的结果
网站: “http://bato.to/comic/_/nisekoi-r951”
代码:
public string DownloadString(string add)
{
string html = "";
using (WebClient client = new WebClient())
{
client.Proxy = null;
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
while (html=="")
{
try
{
html = client.DownloadString(add);
//MessageBox.Show(html);
}
catch
{
html = "";
}
}
client.Dispose();
}
return html;
}
谢谢你的帮助。
其实是否返回*空*或者它抛出一个异常,并因此设置为空字符串? – Blorgbeard 2015-03-31 01:02:59
首先将'httl://'转换为'http://' – SimpleVar 2015-03-31 01:03:30
它返回null,因为它在其他网站上有效。 – NoobCS 2015-03-31 01:03:37