简体   繁体   中英

.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."

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

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 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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