Webclient 下载字符串 returns 意外结果
Webclient Download String returns unexpected results
我有这个功能可以下载网站的 html 代码,但是当我输入这个特定网站时,它 returns 一个点 (.) 而不是 html 代码,可以谁能告诉我哪里错了或者为什么不重新调整代码?
网站:"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;
}
感谢您的帮助。
您需要在该站点上使用 "https":
public static string DownloadString(string add)
{
using (var client = new WebClient())
{
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
return client.DownloadString(add);
}
}
调用代码:
Console.WriteLine(DownloadString("https://bato.to/comic/_/nisekoi-r951"));
响应示例:
<div class='ipbfs_login_col'>
<input type='checkbox' id='inline_invisible' name='anonymous
' value='1' class='input_check left' />
<div style='padding-left: 20px;'>
<label for='inline_invisible'>
<strong>Sign in anonymously</strong>
<span class='desc lighter' style='display: block; pa
dding-top: 5px;'>Don't add me to the active users list</span>
</label>
</div>
</div>
我有这个功能可以下载网站的 html 代码,但是当我输入这个特定网站时,它 returns 一个点 (.) 而不是 html 代码,可以谁能告诉我哪里错了或者为什么不重新调整代码?
网站:"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;
}
感谢您的帮助。
您需要在该站点上使用 "https":
public static string DownloadString(string add)
{
using (var client = new WebClient())
{
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
return client.DownloadString(add);
}
}
调用代码:
Console.WriteLine(DownloadString("https://bato.to/comic/_/nisekoi-r951"));
响应示例:
<div class='ipbfs_login_col'>
<input type='checkbox' id='inline_invisible' name='anonymous
' value='1' class='input_check left' />
<div style='padding-left: 20px;'>
<label for='inline_invisible'>
<strong>Sign in anonymously</strong>
<span class='desc lighter' style='display: block; pa
dding-top: 5px;'>Don't add me to the active users list</span>
</label>
</div>
</div>