Instant messaging software such as QQ and Baidu Hi have such functions. You click some buttons on the client, and the Web pages opened are all logged on, because the client has logged on, you do not need to log on again on the webpage.
Today, I learned about this problem from a netizen on Baidu, so I took the time to study it and help solve it.
It is also relatively easy to implement with C # (but there is a condition that no verification code is available during webpage login), that is, to log in with httpwebrequest to obtain the cookie value, then, write the cookie to the cookie directory of the browser, and then open the browser. The following is the implementationCodeIf you have any questions, please leave a message.
Code
Using System. IO;
UsingSystem. text;
UsingSystem. net;
UsingSystem. runtime. interopservices;
ClassLogin
{
[dllimport ( " wininet. DLL " , charset = charset. auto, setlasterror = true )]
Public static extern bool internetsetcookie ( string lpszurlname, string lbszcookiename, string lpszcookiedata );
Public Static VoidMain ()
{
Cookiecollection mycookies = New Cookiecollection (); // Cookie set
Byte [] Data = Encoding. ASCII. getbytes ( " Username = xxxxxx & Password = ******** " ); // Username and password information
String URL = @" Http://www.xxx.com /...... " ; // Action address of the login form
Httpwebrequest myrequest = (Httpwebrequest) webrequest. Create (URL );
Myrequest. Method= "Post";
Myrequest. contenttype= "Application/X-WWW-form-urlencoded";
Myrequest. contentlength=Data. length;
Myrequest. cookiecontainer= NewCookiecontainer ();
Try
{
Stream newstream=Myrequest. getrequeststream ();
Newstream. Write (data,0, Data. Length );
Newstream. Close ();
}
Catch(Webexception)
{
Throw NewWebexception ("Network Connection error!");
}
Httpwebresponse myresponse=(Httpwebresponse) myrequest. getresponse ();
Mycookies. Add (myresponse. Cookies );//Add cookie
Foreach(CookieInMycookies)//Set a cookie as a browser cookie
{
Internetsetcookie (
"Http ://" +Cookie. domain. tostring (),
Cookie. Name. tostring (),
Cookie. value. tostring ()+ "; Expires = sun, fig 00:00:00 GMT");
}
System. Diagnostics. process. Start ("Http://www.XXX.com/");//Open a browser
}
}