.net webclient javascript问题 [英] .net webclient javascript problem

查看:69
本文介绍了.net webclient javascript问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过.net中的webclient访问网站,但是却收到一条错误消息,内容如下:"Microsoft Online Services要求使用JavaScript登录.此Web浏览器不支持JavaScript,或者脚本被阻止."

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);   

感谢您的帮助.我应该更换用户代理还是尝试其他方法?在此先感谢Laziale

Any help is appreciated. Should I change the user agent or try something else? Thanks in advance, Laziale

推荐答案

您可能要使用

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.

因此,通过您的 WebClient 将URL文件下载到计算机中的文件中,然后使用 WebBrowser 导航到下载的文件.
它将解析Javascript和其他内容,完成后(必须有一个事件),您可以检索(解析的)内容并使用它.

So, with your WebClient download the URL file to a file in the computer and use the WebBrowser to Navigate 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.

整个您必须启用Java脚本功能"被Java脚本隐藏.
并非服务器是检测到它的人.

That whole "you must enable Javascript thing" is hidden by a Javascript.
It's not the server the one who detects it.

这篇关于.net webclient javascript问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆