尝试获取网页源代码时出现500错误

时间:2014-11-10 06:26:29

标签: asp.net vb.net webclient

我正在尝试获取显示道路状况的网页的源代码。该页面在IE和Firefox中加载正常,但在我的程序尝试访问它时会抛出500错误。当我的程序试图访问它时为什么会抛出错误,但是当我在常规浏览器中打开页面时却不会抛出错误?

Dim rcrawtext As String
    rcrawtext = New System.Net.WebClient().DownloadString("http://traveler.modot.org/report/modottext.aspx?type=condition")

2 个答案:

答案 0 :(得分:0)

他们的查询没问题,问题是你正在使用的URL,它没有重定向到有效页面

Dim rcrawtext As String
 rcrawtext = New System.Net.WebClient().DownloadString("http://stackoverflow.com/questions/26837965/vb-net-500-error-when-trying-to-get-source-code-of-webpage-webpage-works-in-r")

答案 1 :(得分:0)

您使用的是WebBrowser吗?

是?只需使用WebBrowser.DocumentText

Dim rcrawtext As String = WebBrowser1.DocumentText

没有?只需通过代码创建一个,而无需查看。

Dim WebBrowser1 As New WebBrowser

AddHandler WebBrowser1.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted
WebBrowser1.Navigate("http://traveler.modot.org/report/modottext.aspx?type=condition")

Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
    ' Same code above
End Sub