-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