C# Webclient下载字符串返回意外结果
我有这个功能来下载一个网站的html代码,但是当我输入这个特定的网站时,它会返回一个点(.)而不是html代码,有人能告诉我哪里错了,或者为什么不重新调整代码吗 网站:“ 代码: 谢谢你的帮助 您需要在该站点上使用“https”:C# Webclient下载字符串返回意外结果,c#,webclient,C#,Webclient,我有这个功能来下载一个网站的html代码,但是当我输入这个特定的网站时,它会返回一个点(.)而不是html代码,有人能告诉我哪里错了,或者为什么不重新调整代码吗 网站:“ 代码: 谢谢你的帮助 您需要在该站点上使用“https”: public static string DownloadString(string add) { using (var client = new WebClient()) {
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>
匿名登录
不要将我添加到活动用户列表中
它实际返回null,还是抛出异常并因此设置为空字符串?首先,httl://
进入http://
它返回null是因为它在其他网站上工作。不要说它返回null是因为它在其他网站上工作,假设它返回null,因为它没有命中catch子句中的断点。是吗?这不是一个有效的逻辑链。您是否设置了断点并验证了DownloadString
执行后html==null
,并且未命中catch块?
<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>