Www.cctry.com Post Tutorial
Note that this article is not a tutorial
//in thehttp://www.idc3389.com/user/modify.aspSource Code//Find user Data inCString finduserinfo (CString strelemet,cstring strhtmlsrc) {if(Strelemet = = L""|| STRHTMLSRC = = L""){ returnNULL; } intpos =Strhtmlsrc.find (Strelemet); if(pos = =-1) { returnNULL; } POS= pos + strelemet.getlength () +8;//_value= "UINT len =strhtmlsrc.getlength (); STRHTMLSRC= Strhtmlsrc.right (Len-POS); POS= Strhtmlsrc.find (L"\""); STRHTMLSRC=Strhtmlsrc.left (POS); //AfxMessageBox (STRHTMLSRC); returnstrhtmlsrc;}
Crawled Packets
//The following are the request headers:POST http://www.idc3389.com/user/userlogin.asp http/1.1Host:www.idc3389.comConnection:keep-alivecontent-length: theCache-control:max-age=0Accept:text/html,application/xhtml+xml,application/xml;q=0.9, image/webp,*/*; Q=0.8origin:http://www.idc3389.comuser-agent:mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/33.0.1750.146 bidubrowser/6.x safari/537.36content-type: Application/x-www-form-urlencodedreferer:http://www.idc3389.com/accept-encoding:gzip,deflateaccept-language:zh-cn,zh;q=0.8cookie:pgv_pvid=9485415913; pgv_pvi=1262146560; Aspsessionidaqctddqd=nbanefebeofjhgfbanhaddko; __qc_wid=959; iesession=alive; pgv_si=s8099517440username=username&password=password&screenwidth=&screenheight=&submit.x=29 &submit.y=12//below is the answer header: http/1.1 302 Object Moveddate:sun, Oct 14:10:22 gmtserver:microsoft-iis/ 6.0x-powered-by:asp. Netlocation:logininfo.aspcontent-length:134content-type:text/htmlcache-control:private
The main code is as follows, making a simple comment
/*the HTTP request method provided by the HTTP1.1 protocol has options,, POST, PUT, DELETE, TRACE, CONNECT. Where post is typically used to submit data to the server, this article discusses several ways to submit data in the post. We know that the HTTP protocol is an ASCII code transmission, based on the TCP/IP Protocol Application layer specification. The specification divides the HTTP request into three parts: a status line, a request header, and a message body. The protocol specifies that the data submitted by the POST must be placed in the message body (entity-body), but the protocol does not specify what encoding the data must use. In fact, the developer can completely decide the format of the message body, as long as the last HTTP request satisfies the above format. However, the data sent out, but also the service side of the success of the analysis is meaningful. General Service-side languages such as PHP, Python, and their framework have built-in features that automatically parse common data formats. The server is typically based on the Content-type field in the request header (headers) to learn how the message body in the request is encoded and then parses the subject. So when it comes to the POST submission data scheme, it contains two parts: the Content-type and the message body encoding method. */#import"C:\\windows\\syswow64\\winhttp.dll"No_namespacevoidCidc3389logindlg::onbnclickedbutton1 () {CString strusername, strpassword; GetDlgItemText (Idc_edit1, strUserName); GetDlgItemText (Idc_edit2, strpassword); if(strUserName = = L""|| L""==strpassword) {MessageBox (L"account or password cannot be empty"); return; } CoInitialize (NULL); Iwinhttprequestptr Phttpreq=NULL; HRESULT HR=phttpreq.createinstance (__uuidof (winhttprequest)); if(FAILED (HR)) {couninitialize (); } HR= Phttpreq->open (L"POST", L"http://www.idc3389.com/user/userlogin.asp"); if(FAILED (HR)) {couninitialize (); } //note here to set Content-type//content-type:application/x-www-form-urlencodedPhttpreq->setrequestheader (L"Content-type", L"application/x-www-form-urlencoded"); //send a POST requestCString Strpost; Strpost.format (L"username=%s&password=%s&screenwidth=&screenheight=&submit.x=38&submit.y=14", strUserName, strpassword); variant_t Varpost; Varpost=Strpost; HR= phttpreq->Send (varpost); if(FAILED (HR)) {couninitialize (); } // //Determine whether the login is successful by the status code;//Long status =-1;//Phttpreq->get_status (&status);//if (status! =) {//MessageBox (L "Login failed! Please check the user name and password is wrong! ");//goto _exit0;// } //Syc boss method, get page elements, to determine whether there is a "welcome you", this is the Web site for the source code. //Different sites treated differently_variant_t varrspbody = phttpreq->Getresponsebody (); ULONG Datalen= varrspbody.parray->rgsabound[0].celements; Char*pcontentbuffer = (Char*) varrspbody.parray->PvData; CString Strcntbuffer; Strcntbuffer=Pcontentbuffer; CString Strsuckey (_t ("you are welcome:")); if(Strcntbuffer.find (strsuckey)! =-1) {GetDlgItem (idc_edit1)-EnableWindow (FALSE); GetDlgItem (IDC_EDIT2)-EnableWindow (FALSE); MessageBox (_t ("Landing Success! ")); } Else{MessageBox (_t ("Login failed! ")); } //get user Information after successful loginhr = Phttpreq->open (L"GET", L"http://www.idc3389.com/user/modify.asp"); if(FAILED (HR)) {couninitialize (); } HR= phttpreq->Send (); if(FAILED (HR)) {couninitialize (); } //Solve garbled problemsVarrspbody = phttpreq->Getresponsebody (); Datalen= varrspbody.parray->rgsabound[0].celements; Pcontentbuffer= (Char*) varrspbody.parray->PvData; CString strhtmlsrc; STRHTMLSRC=Pcontentbuffer; //name, ID, EMAIL, TELCString strelement= L"id=\ "Truename\""; CString Struserinfo=Finduserinfo (strelement, STRHTMLSRC); GetDlgItem (Edit_truename)-SETWINDOWTEXTW (Struserinfo); Strelement= L"id=\ "Address\""; Struserinfo=Finduserinfo (strelement, STRHTMLSRC); GetDlgItem (edit_address)-SETWINDOWTEXTW (Struserinfo); Strelement= L"id=\ "Mobi\""; Struserinfo=Finduserinfo (strelement, STRHTMLSRC); GetDlgItem (Edit_tel)-SETWINDOWTEXTW (Struserinfo); Strelement= L"id=\ "Email\""; Struserinfo=Finduserinfo (strelement, STRHTMLSRC); GetDlgItem (Edit_e_mail)-SETWINDOWTEXTW (Struserinfo); CoUninitialize (); //Uninstall the COM component when you close it}
Post Tutorial Notes-POST Method login website