Basic implementation of the function has been finished, basically can copy the paste to complete the process of login Baidu
Today's this post to say how to get Baidu's verification code
Content Review : Remember the first Post said that if the login exception, Baidu will send back 2 values? Yes, the two values are CodeType and codestring, which can be obtained with the previous JSON data parsing.
It also says that CodeType is immutable (at least the same time as the same request). Request verification code will be required to pass this parameter, so to get the correct verification code, this parameter is necessary, otherwise you request how many times is a wrong verification code!
specific code into the following :
//Package replacement Verification Code
public void Regetcode ()
{
String Reset_code = String. Format ("Https://passport.baidu.com/v2/?reggetcodestr&token={0}&tpl=zongheng&apiver=v3&tt={1} &FR=LOGIN&VCODETYPE={2}&CALLBACK=BD__CBS__TA1XSS ", token, Utility.gettimestamp (), vcodetype);
String codecontent = Helper. Getpageresponse_get (Reset_code, Utility.urldecode ("http://passport.zongheng.com/?location=http%3A%2F% 2fwww.zongheng.com%2f ")," */* ");
if (_regex. IsMatch (codecontent))
Codecontent = _regex. Match (codecontent). Value;
var coderesult = jsonconvert.deserializeobject<reget_code> (codecontent);
_codestring = CODERESULT.DATA_CODE.VERIFYSTR;
String Url_newcode = String. Format ("https://passport.baidu.com/cgi-bin/genimage?{ 0} ", _codestring);
Bitmap bp= Helper. GetCode (Url_newcode, Utility.urldecode ("Http://passport.zongheng.com/?location=http%3A%2F%2Fwww.zongheng.com%2F "));
pictureBox1.Image = BP;
}
It may look like this alone, some people will not understand what meaning, here is a comment
The Reset_code is the Web page that represents the codestring, followed by the tokens that were obtained earlier, the timestamp generated, and the CodeType
The codecontent represents what is returned after the page is requested, and the parameter is the one required for the Post method of the previous Httphelper class.
The next step is to analyze the content, get the codestring, and then re-initiate the request to the image page of the CAPTCHA and display the verification code back to PictureBox
As for the CodeType, this happens when the request is logged in, the exception is returned
Here's how to verify that the verification code is correct, press ENTER after the text box has entered a verification code
private void Txtcode_keydown (object sender, KeyEventArgs e)
{
if (E.keycode = = Keys.enter)
{
Thread th_2 = null;
if (E.keycode = = Keys.enter)
{
th_2 = new Thread (() =
{
Verifycode = Txtcode. Text;
First check the Verification Code check page to see if the verification code is correct
String Url_checkcode = String. Format ("https://passport.baidu.com/v2/?checkvcode&token={0}&tpl=zongheng&apiver=v3&tt={1}& Verifycode={2}&codestring={3}&callback=bd__cbs__nm74kc ", token, Utility.gettimestamp (), Verifycode, _ codestring);
String checkcode = Helper. Getpageresponse_get (Url_checkcode, Utility.urldecode ("http://passport.zongheng.com/?location=http%3A%2F% 2fwww.zongheng.com%2f ")," */* ");
if (_regex. IsMatch (Checkcode))
Checkcode = _regex. Match (Checkcode). Value;
var code_msg = jsonconvert.deserializeobject<checkvcode> (Checkcode);
Codemsg (code_msg. errinfo.no);
if (code_msg. Errinfo.no! = "0")
Return
LoginStatus status = Login (Verifycode, _codestring, token, Raskey, userindex);
Gocomment_page (status);
Th_2.abort ();
});
Th_2.start ();
Th_2.isbackground = true;
}
}
OK, today is here, if there is a problem, welcome comments Exchange ~
C # simulation Baidu Login and comment on the designated website replies (iv)