.net webclient javascript问题
我正在尝试通过 .net 中的 webclient 访问网站,但收到一条错误消息: “Microsoft Online Services 需要 JavaScript 才能登录。此 Web 浏览器不支持 JavaScript,或者脚本被阻止。”
以下是我用于访问该网站的代码:
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);
如有任何帮助,我们将不胜感激。我应该更改用户代理还是尝试其他方法? 提前致谢,拉齐亚莱
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."
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要使用
System.Windows。 Forms.WebBrowser
解析 Javascript。Web 客户端仅尝试下载文件。
JavaScript 不在服务器上处理...它们在客户端上处理。
因此,使用您的
WebClient
将 URL 文件下载到计算机中的文件中,并使用WebBrowser
导航
到下载的文件。它将解析 Javascript 和其他内容,完成后(必须有一个事件),您可以检索(解析后的)内容并使用它。
整个“你必须启用 Javascript 的东西”被 Javascript 隐藏了。
检测到它的不是服务器。
You might want to use a
System.Windows.Forms.WebBrowser
to parse the Javascript.A web client only attempts downloads the file.
Javascripts are not processed on the server... They are processed on the client.
So, with your
WebClient
download the URL file to a file in the computer and use theWebBrowser
toNavigate
to the downloaded file.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.
That whole "you must enable Javascript thing" is hidden by a Javascript.
It's not the server the one who detects it.