1
无论我使用WebClient
还是HttpWebRequest
,加载此页超时。我究竟做错了什么?它不能是https
,因为其他https
网站加载得很好。无法使用WebClient或HttpWebRequest加载页面
下面是我最近的一次尝试,它添加了我在Firefox的检查器中看到的所有标头。
一个有趣的现象是,我无法使用Fiddler来监控它,因为当Fiddler运行时,一切正常。
Using client As WebClient = New WebClient()
client.Headers(HttpRequestHeader.Accept) = "text/html, image/png, image/jpeg, image/gif, */*;q=0.1"
client.Headers(HttpRequestHeader.UserAgent) = "Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12"
client.Headers(HttpRequestHeader.AcceptLanguage) = "en-US;en;q=0.5"
client.Headers(HttpRequestHeader.AcceptEncoding) = "gzip, deflate, br"
client.Headers(HttpRequestHeader.Referer) = "http://www.torontohydro.com/sites/electricsystem/Pages/foryourhome.aspx"
client.Headers("DNT") = "1"
client.Headers(HttpRequestHeader.KeepAlive) = "keep-alive"
client.Headers(HttpRequestHeader.Upgrade) = "1"
client.Headers(HttpRequestHeader.CacheControl) = "max-age=0"
Dim x = New Uri("https://css.torontohydro.com/")
Dim data as string = client.DownloadString(x)
End Using
所有这些都是多余的代码。把它煮成几条线会导致相同的挂起。
Using client as WebClient = New WebClient()
Dim data as string = client.DownloadString("https://css.torontohydro.com")
End Using
这是HttpWebRequest
代码,概括地说,这也挂得到响应。
Dim getRequest As HttpWebRequest = CreateWebRequest("https://css.torontohydro.com/")
getRequest.CachePolicy = New Cache.RequestCachePolicy(Cache.RequestCacheLevel.BypassCache)
Using webResponse As HttpWebResponse = CType(getRequest.GetResponse(), HttpWebResponse)
'no need for any more code, since the above line is where things hang
为什么要为VB.Net代码道歉? – N0Alias
你只是想要网页的HTML? – Codexer
对不起,正试图做一个坏笑话。我有几页要阅读该网站,但甚至无法通过第一页。似乎是特定的网站。无论我设置所有这些标题还是仅使用最后两行,我都会得到相同的超时时间。或者,如果我使用'HttpWebRequest'和'GET'方法。 – deanis