简体   繁体   English

.net webclient javascript问题

[英].net webclient javascript problem

I am trying to access a website via webclient in .net but I am getting an error message saying this: "Microsoft Online Services requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked." 我试图通过.net中的webclient访问一个网站,但我收到一条错误消息,说: “Microsoft Online Services需要JavaScript才能登录。这个Web浏览器不支持JavaScript,或者脚本被阻止。”

Here is the code I am using to access the website: 这是我用来访问网站的代码:

string url = "myUrl";
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; rv:5.0.1) Gecko/20100101 Firefox/5.0.1");
client.Credentials = new NetworkCredential("username", "Password");          
string lines = client.DownloadString(url);   

Any help is appreciated. 任何帮助表示赞赏。 Should I change the user agent or try something else? 我应该更改用户代理还是尝试别的? Thanks in advance, Laziale 提前谢谢,Laziale

You might want to use a System.Windows.Forms.WebBrowser to parse the Javascript. 您可能希望使用System.Windows.Forms.WebBrowser来解析Javascript。
A web client only attempts downloads the file. Web客户端仅尝试下载文件。
Javascripts are not processed on the server... They are processed on the client. Javascripts不在服务器上处理......它们在客户端上处理。

So, with your WebClient download the URL file to a file in the computer and use the WebBrowser to Navigate to the downloaded file. 因此,使用WebClient将URL文件下载到计算机中的文件,并使用WebBrowser Navigate到下载的文件。
It will parse the Javascripts and other stuff and after finished (there must be an event for that) you can retrieve the (parsed) content and work with it. 它将解析Javascripts和其他东西,完成后(必须有一个事件),你可以检索(解析)内容并使用它。

That whole "you must enable Javascript thing" is hidden by a Javascript. 整个“你必须启用Javascript的东西”被Javascript隐藏。
It's not the server the one who detects it. 检测它的人不是服务器。

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

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