我的VB.Net应用程序出了问题。当我试图在没有代理的情况下向http://ask.fm发送请求时,我在fiddler中得到以下响应:HTTP / 1.1 502 Fiddler - DNS查找失败
这是什么意思?为什么在为请求使用代理服务器时没有错误?
我使用以下代码发送请求:
Public Function GetRequest(ByVal url As String, ByVal referer As String, ByVal cookie As CookieContainer, Optional proxy As String = "") As String
Dim request As HttpWebRequest
Dim response As HttpWebResponse
Try
Dim cookies As String = ""
request = CType(HttpWebRequest.Create(url), HttpWebRequest)
request.CookieContainer = cookie
request.ServicePoint.Expect100Continue = False
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0"
If referer <> "" Then
request.Referer = referer
End If
request.Timeout = 10000
If proxy <> "" Then
request.Proxy = New WebProxy(proxy)
End If
response = CType(request.GetResponse(), HttpWebResponse)
cookies = response.GetResponseHeader("Set-Cookie")
If url.Contains("ask.fm/") Then
If New Regex("l=.*?; domain=ask.fm; path=/;").Match(cookies).Value = "" Then
Return "ERROR"
End If
End If
Dim source As String = New StreamReader(response.GetResponseStream()).ReadToEnd()
If source.Contains("No robots allowed!") Then
source = "ERROR"
End If
If source = "" Then
source = "ERROR"
End If
Return source
Catch ex As Exception
Return "ERROR"
End Try
End Function
答案 0 :(得分:0)
您是否正在使用 Fiddler 来检查流量?如果是这样,请确保Fiddler可以正确地重定向您的流量。
转到帮助&gt;关于Fiddler 并确保您的网关正确(如果您可以直接访问,则设置为您用于访问互联网的代理或等于无网关)。