vb.net - WebRequest.GetResponse - 远程服务器返回错误 : (404) Not Found

标签 vb.net webrequest

我正在尝试连接到网站,但即使我可以在浏览器中访问该网站,它仍然会返回此错误:

An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

Additional information: The remote server returned an error: (404) Not Found.

我很确定我的代码是正确的,因为我最近经常使用相同的代码,但无法弄清楚为什么它返回错误,有什么建议吗? 我的代码:

OddsTodayREQUEST = WebRequest.Create("http://www.betexplorer.com/next/soccer/")
Using OddsTodayRESPONSE As WebResponse = OddsTodayREQUEST.GetResponse()
            Using OddsTodayREADER As New StreamReader(OddsTodayRESPONSE.GetResponseStream())
                OddsTodayHTML = OddsTodayREADER.ReadToEnd()
            End Using
        End Using

最佳答案

该站点希望将用户代理添加到请求中。您可以通过谷歌搜索我的用户代理是什么?找到您自己的用户代理并按如下方式添加:

OddsTodayREQUEST.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)"

关于vb.net - WebRequest.GetResponse - 远程服务器返回错误 : (404) Not Found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46104734/

相关文章:

vb.net - 将多行添加到 SMTP 电子邮件 VB.NET 的正文

c# - WCF 数据限制

c# - 将 C# 转换为 vb.net 错误

c# - 有没有办法传递登录信息来阅读 C# 中的网站

Python BeautifulSoup 检查输出

.net - WinSCP上传文件到远程SFTP错误: "Cannot create remote file – Permission denied"

.net - 如何使用自定义结构代替 KeyValuePair?

c# - 尝试 POST 到 RESTful 服务时尝试 webRequest.GetRequestStream 时发生 System.Net.WebException

c# - 如何在.net 上为WebClient 设置超时?

c# - 如何测试客户端可以保持 HTTPS 连接打开多长时间?