Register get Cookie Get Formhash go to register

Source: Internet
Author: User
Tags cdata

Click to open link

void Cmyregdlg::onbnclickedbutton1 ()//get cookie {//TODO: Add control Notification Handler code here//Build login form data char *action= "/d/u
    Pload/"; Char *headers= "accept:image/gif, Image/x-xbitmap, Image/jpeg, Image/pjpeg, Application/x-shockwave-flash, */*\r\n" "A ccept-language:zh-cn\r\n "//" Accept-encoding:gzip, deflate\r\n "" user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
 
    SV1) \ r \ n "" host:192.168.0.21\r\n "" connection:keep-alive\r\n\r\n ";
CString szheaders (headers); szheaders=headers;//.
 
    Format (HEADERS,NREADLENGTH,SID); chttpfile* pFile = pconnection->openrequest (chttpconnection::http_verb_get,action,null,1,null,null,internet_ flag_no_cookies| internet_flag_keep_connection|
    Internet_flag_no_auto_redirect);
    Pfile->sendrequest (Szheaders,null,null);
    Szheaders.releasebuffer ();
    CString header ("");//Get landing results in header pfile->queryinfo (http_query_raw_headers_crlf,header,0);
    Pfile->close ();
    Delete PFile; int I=hEader.
    Find ("Set-cookie:");
        if (i>=0) {i+=12; Cookie1_value=header. Mid (I,header.
         Find (";", I)-i); int J=header.
        Find ("Set-cookie:", i);
            if (j>=0) {j+=12; Cookie2_value=header. Mid (J,header.
        Find (";", j)-j); }} header.
    ReleaseBuffer (); UpdateData (FALSE);//update} void Cmyregdlg::onbnclickedbutton2 ()//get formhash {//TODO: In this Add control notification handler code int Nrea
    dlength = 0; Build login form data char *action= "/d/upload/register.php?infloat=yes&handlekey=register&inajax=1&ajaxtarget=f
    Win_content_register "; Char *headers= "Accept: */*\r\n" "accept-language:zh-cn\r\n" "referer:http://127.0.0.1/d/upload/\r\n" "Accept -encoding:gzip, deflate\r\n "" user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
 
    SV1) \ r \ n "" host:127.0.0.1\r\n "" connection:keep-alive\r\n "" Cookie:%s\r\n\r\n ";
    CString szheaders; Szheaders.format (Headers,cookIe1_value,cookie2_value); chttpfile* pFile = pconnection->openrequest (chttpconnection::http_verb_get,action,null,1,null,null,internet_ flag_no_cookies| internet_flag_keep_connection|
    Internet_flag_no_auto_redirect);
    Pfile->sendrequest (Szheaders,null,null);
 
    Szheaders.releasebuffer ();
    CString data ("");//Get Landing Results page Char szbuff[1025];
       while (1) {nreadlength = Pfile->read (Szbuff, 1024);
       if (nreadlength==0) break;
       szbuff[nreadlength]= ' + ';
    Data=data+szbuff;
    } pfile->close ();
 
    Delete PFile; int I=data.
    Find ("Formhash");
        if (i>=0) {i+=17; Formhash_value=data. Mid (I,data.
        Find ("\" ", I)-i);
    UpdateData (NULL); } data.
 
ReleaseBuffer (); } void Cmyregdlg::onbnclickedbutton3 ()//go to register {//TODO: Add control Notification Handler code here//Build login form data char *acti
    On= "/d/upload//register.php?regsubmit=yes&inajax=1"; Char *headers= "Accept:image/gif, Image/x-xbitmap,Image/jpeg, Image/pjpeg, Application/x-shockwave-flash, */*\r\n "" referer:http://127.0.0.1/d/upload/index.php\r\n " "Accept-language:zh-cn\r\n" "content-type:application/x-www-form-urlencoded\r\n"//"Accept-encoding:gzip, DE Flate\r\n "" user-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) \ r \ n "" host:127.0.0.1\r\n "" Content-length:%d\r\n "" connection:keep-alive\r\n "" cache-control:no-c Ache\r\n "" Cookie:%s;
 
    %s\r\n ";
    Char *form1= "formhash=%s"; Char *form2= "&referer=http%3A%2F%2F127.0.0.1%2Fd%2Fupload%2findex.php&handlekey=register& Activationauth=&username=test2&password=test&password2=test&email=test2@mail.com®submit=%cc%e1
    %BD%BB ";
    CString Formdata; Formdata.
    Format (Form1,formhash_value); Formdata.
    Append (Form2); int Nreadlength=formdata.
 
    GetLength ();
    CString szheaders;
 
    Szheaders.format (Headers,nreadlength,cookie1_value,cookie2_value);    chttpfile* PFile =Pconnection->openrequest (chttpconnection::http_verb_post,action,null,1,null,null,internet_flag_no_cookies| internet_flag_keep_connection|
    Internet_flag_no_auto_redirect); Pfile->sendrequest (Szheaders, (LPVOID) formdata.
     
    GetBuffer (), nreadlength);
    Szheaders.releasebuffer (); Formdata.
 
    ReleaseBuffer ();
    CString data ("");//Get Landing Results page Char szbuff[1025];
       while (1) {nreadlength = Pfile->read (Szbuff, 1024);
       if (nreadlength==0) break;
       szbuff[nreadlength]= ' + ';
    Data=data+szbuff;
    } pfile->close ();
    Delete PFile; int I=data.
Find ("cdata[");
        cdata[the user name has been registered] if (i>=0) {i+=6; AfxMessageBox (data. Mid (I,data.
    Find ("]", i)-i)); }//if (data. Find ("The user name is already registered") AfxMessageBox ("already exists.")
    "); M_data.
    Setwindowtexta (data); Data.
 
ReleaseBuffer ();
} CInternetSession * session;//Global const int ntimeout = 3000; Session. SetOption (Internet_option_connect_timeout, ntimeout); Wait delay between retries SESsion.   SetOption (Internet_option_connect_retries, 3); The retry count//////above is the session preparation pconnection=session.
GetHttpConnection (Server,port);//Request Pconnection->close ();
Delete pconnection; pconnection=null;//close connection at the end of the request, but do not close the session at this time, more requests can be made: pconnection=session.
GetHttpConnection (Server,port);//Request Pconnection->close ();
Delete pconnection;

pconnection=null;//closes the connection after the request is completed, but does not close the session when all requests are completed session->close (); You do not need to analyze the cookie data as above, because the session is automatically saved and forwarded.



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.