Try
Dim url = "something"
Dim request = WebRequest.Create(url)
request.Credentials = CredentialCache.DefaultCredentials
Dim httpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim dataStream = httpWebResponse.GetResponseStream()
If dataStream Is Nothing Then
Return ""
End If
Dim reader = New StreamReader(dataStream)
Return reader.ReadToEnd()
Catch ex As WebException
Return ""
End Try
上面的代码在LocalHost中工作,但是在服务器中它不工作并抛出异常。
System.Net.WebException'发生在System.dll中但未处理 在用户代码中
答案 0 :(得分:0)
你在Catch
之后重新抛出异常。
删除Throw
。
Try
Dim url = "something"
Dim request = WebRequest.Create(url)
request.Credentials = CredentialCache.DefaultCredentials
Dim httpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim dataStream = httpWebResponse.GetResponseStream()
If dataStream Is Nothing Then
Return ""
End If
Dim reader = New StreamReader(dataStream)
Return reader.ReadToEnd()
Catch ex As WebException
Return ""
End Try