Using WebBrowser to execute JavaScript under WinForm

Source: Internet
Author: User

At present many websites in order to prevent the malicious submission form information, mostly uses the encrypted way to the submission information processing, after the encryption processing passes through the post to the server authentication, this kind of operation is generally uses the javascipt to encrypt, if we want to submit the form to the website correctly, It is necessary to simulate the cryptographic operation of the Javascipt. Then we can also use WebBrowser to execute the JS script, to achieve the purpose of encryption.

Take the mobile mm login to get verification code as an example, briefly describe the process of WebBrowser execution JS. Jquery.ajax ({
URL: "/portal/web/smsrandomsendaction.do",
DataType: "JSON",
Type: "POST",
Data: {
"LoginName": Strenc (LoginName, "1234567", "" "," "),
' Type ': type
},
Success:function (JSON) {
if (Json.ret = = 1) {
Ranpastor.showmessage ("two times to send the download SMS clearance can not be less than 1 minutes");
Ranpastor.disabled (); Limit times exceeded cannot be sent again, cannot be sent
Return
}
if (Json.ret = = 0) {//Confirm send SMS secret success, can be short input the letter, 60 seconds can be sent again
Ranpastor.disabled ();//Failure
Ranpastor.startautomaticavailable ();//Start auto-restore Active state
var message = "The verification code has been issued, as you"
Message + = ' <span id= ' resend_time_count ' > ' +ranpastor.disabledtime+ ' </span> ';
Message + = "The second has not been received, please click the button to regain";
Ranpastor.showmessage (message);
} else {//send failed, can resend
var message = Json.message | | "Send failed!" "
if (Json.ret = = 5) {
Message = ' You have issued a text message password more than the maximum number of SMS password issued, please use the last time you received the SMS password, or use a fixed password to log in, if you do not remember the fixed password, please use your phone to send SMS "czmm" to "10658800", The system will automatically issued you a new fixed password to your mobile phone, thank you for your support! '
}
Ranpastor.available ();
Ranpastor.showmessage (message);
}
return false;
The above code is the JS code used to get the verification code for moving mm, and we can see in the code that the LoginName is STRENC encrypted and submitted to the website in the process. While Strenc is provided by http://mm.10086.cn/moneditor/cs/include/js/common/core/core.js, we only need to execute this strenc to get encrypted ciphertext. First, let's write an HTML that executes strenc to facilitate our invocation.

First set the window class to COM accessible

[System.Runtime.InteropServices.ComVisibleAttribute (True)]public partial class Frmdemo:form

Then put the JS code that we wrote before in the WebBrowser.

webbrowser1.documenttext="";
Here, the preparation has been done, the next is to call this JS function problem. In WebBrowser, we can call JS like this
WebBrowser1.Document.InvokeScript ("Getpwd", new object[] {"18780110000"})

Returns the value of an object, which must be returned as an encrypted string and converted to a string.

Note that the calling code is not written in the Form_Load event.

Source: http://www.cnblogs.com/Dersoul/archive/2011/11/27/2265142.html

Using WebBrowser to execute JavaScript under WinForm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.