简体   繁体   English

WebClient.DownloadString不返回任何数据

[英]WebClient.DownloadString returning no data

I'm experiencing a strange issue with WebClient.DownloadString that I can't seem to solve, my code: 我遇到了一个我无法解决的WebClient.DownloadString的奇怪问题,我的代码:

Dim client As New WebClient()
Dim html = client.DownloadString("http://www.btctrade.com/")

The content doesn't seem to be fully AJAX, so it can't be that. 内容似乎不是完全AJAX,所以它不可能。 Is it due to the web page being in Chinese? 是因为网页是中文的吗? I'm guessing HTML is just served as HTML, so can't really be that either. 我猜测HTML只是作为HTML提供,所以也不可能。 The URL is fine when I go to it and there seems to be no redirects to https either. 当我去它时,URL很好,似乎没有重定向到https。

Anyone know why this is happening? 任何人都知道为什么会这样吗?

You must set cookies and useragent in the webclient headers this works 您必须在webclient标头中设置cookie和useragent

client .Headers.Add(HttpRequestHeader.UserAgent, "UserAgent,Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1");
client .Headers.Add(HttpRequestHeader.Cookie, "USER_PW=9b1283bfe37ac47b243a1e0c9c1c9e52; PHPSESSID=f692406a0c84dba2605a7065d55a3b53")

and if u want that the request do all this work , you have to user httpwebrequest then save all the response's headers and use them in a new request 如果您希望请求完成所有这些工作,您必须使用httpwebrequest然后保存所有响应的标头并在新请求中使用它们

WebClient is not buggy, so probably the server is returning data you did not expect. WebClient没有错误,所以服务器可能正在返回您不期望的数据。 Use Fiddler to watch what happens when you go to the site in a web browser. 使用Fiddler观察当您在Web浏览器中访问该站点时会发生什么。

When I executed your code the web site returned no data. 当我执行您的代码时,网站没有返回任何数据。 When I visited the site in a web browser it returned data. 当我在Web浏览器中访问该站点时,它返回了数据。 Probably, the site is detecting that you are a bot and denying you access. 可能是该网站检测到您是机器人并拒绝您访问。 Fake being a browser by mimicking what you see in Fiddler. 通过模仿你在Fiddler中看到的东西伪造成浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM