VC post form -- logon verification Sina mail

Source: Internet
Author: User

1. Local Environment:

Windows XP SP3 and ADSL

 

2. Development tools:

Wildpackets omnipeek v5.1.4

Visual c ++ 6.0

Ie6.0

Flexedit v2.3.1871

 

If you feel that the omnipeek file is too large to download friends, you can use the open source simple packet capture analysis tool, first log on to codeproject, then click here to download or mail me for source code (ningyusky@tom.com or koma0769@vip.qq.com)

 

Note: If you have not logged on to the codeproject, you cannot download it. You can modify the source code of the tool and record all the data of get and post operations in a file, to view the analysis .....

 

This is what I do, because my hardware configuration is not very "mainstream", so every time omnipeek starts and creates a project, the computer is about to crash .....

 

3. program running effect:

 

 

4. Source Code Description:

 

Although there are more than one hundred lines of code in such a short time, I debugged it for more than three hours to solve each of the errors that may exist here, I hope to discuss with you ......

/*************************************** *******************************/<Br/> /* function Description: simulate the post form -- log on to Sina mail <br/>/* parameter number: None <br/>/* return value: None <br/>/*: koma 2009.10.16 <br/> /******************************** **************************************** /<br/> void csinadlg:: onok () <br/>{< br/> // todo: add extra validation here <br/> updatedata (true); <br/> If (m_struser.isempty ()) {<br/> MessageBox ("the email user name cannot be blank "," Prompt "); <br/> m_ctruser.setfocus (); <br/> return; <br/>}</P> <p> If (m_struser.find ("@ Sina") <1) {<br/> MessageBox ("add the suffix of the mailbox name first, for example, @ Sina... "," prompt "); <br/> m_ctruser.setfocus (); <br/> return; <br/>}</P> <p> If (m_strpassword.isempty ()) {<br/> MessageBox ("the email password cannot be blank", "prompt"); <br/> m_ctruser.setfocus (); <br/> return; <br/>}</P> <p> charszaccept [] = "accept: */*"; <br/> charszreferer [] = "Referer: http://mail.sina.com.cn // R/N "; <br/> cstringszformdata = "Domain = sina.cn & logintype = uid & U =" + m_struser + "& domain = Sina.com & psw =" + m_strpassword + "& btnloginfr "; </P> <p> hinternethsession; <br/> hinternet hconnect; <br/> hinternet hrequest; <br/> boolbreturn = false; </P> <p> // previously used socket and now uses wininet APIs to establish a link <br/> hsession = internetopen ("inetall", internet_open_type_preconfig, null, null, 0); <br/> hconnect = internetconnect (hsession, "Ma Il.sina.com.cn ", internet_default_http_port, null, null, internet_service_http, 0, 1); <br/> hrequest = httpopenrequest (hconnect," Post "," cgi-bin/login. cgi ", null," http://www.sina.com.cn ", (lpcstr *) & szaccept, internet_flag_reload, 1 ); </P> <p> // submit a data form <br/> lpvoid pbuf = (lpvoid) szformdata. getbuffer (szformdata. getlength (); <br/> breturn = httpsendrequest (hrequest, "Content-Type: Application/X-WWW-form-urlencode D/R/N ",-1, pbuf, szformdata. getlength (); <br/> If (! Breturn) <br/>{< br/> MessageBox ("An error occurred while sending the HTTP request! "," Prompt ", mb_iconerror | mb_ OK); <br/> return; <br/>}</P> <p> charszrecvbuf [1024]; // accept the data buffer <br/> DWORD dwnumberofbytesread; // server return size <br/> dworddwrecvtotalsize = 0; // accept the total data size <br/> dworddwrecvbuffsize = 0; // accept the size of the Data Buf <br/> cfilem_file; // write the returned data to the file <br/> cstring strtemp; // temporary message box </P> <p> m_file.open ("recvdata. TMP ", cfile: modewrite | cfile: modecreate, null); <br/> memset (szrecvbuf, 0,1024 ); </P> <p> DO <br/> {<br/> // Start reading data <br/> breturn = internetreadfile (hrequest, szrecvbuf, 1024, & dwnumberofbytesread); <br/> If (! Breturn) <br/>{< br/> MessageBox ("internetreadfile error! "," Prompt ", mb_iconerror | mb_ OK); <br/> break; <br/>}</P> <p> // statistics on the size of received data <br/> szrecvbuf [dwnumberofbytesread] = '/0 '; <br/> dwrecvtotalsize + = dwnumberofbytesread; <br/> dwrecvbuffsize + = strlen (szrecvbuf ); </P> <p> // write the buffer to a file <br/> m_file.write (szrecvbuf, strlen (szrecvbuf); <br/> m_file.flush (); <br/>} while (dwnumberofbytesread! = 0); </P> <p> // check whether the received data packet is complete <br/> m_file.close (); <br/> If (dwrecvtotalsize! = Dwrecvbuffsize) <br/>{< br/> MessageBox ("packet loss when receiving data, the returned size is inconsistent! "); <Br/> return; <br/>}</P> <p> cstringstr =" "; // all content <br/> cstringstrline = ""; // single row content <br/> cstdiofilefile; // file object <br/> If (! File. open ("recvdata. TMP ", cfile: moderead | cfile: typetext, null) <br/>{< br/> cstring strtemp; <br/> strtemp. format ("Open File error: % d", getlasterror (); <br/> MessageBox (strtemp); <br/> return; <br/>}</P> <p> // read all TMP content by row <br/> while (file. readstring (strline) <br/>{< br/> STR = STR + strline; <br/>}< br/> file. close (); <br/> wchar_t * pwchar = NULL; <br/> dwordnlen1; </P> <p> // convert the Sina web page UTF-8 format to Unicode <Br/> nlen1 = multibytetowidechar (cp_utf8, 0, STR, str. getlength (), pwchar, 0); <br/> pwchar = new wchar_t [nlen1 + 1]; <br/> memset (pwchar, 0, (nlen1 + 1) * sizeof (wchar_t); <br/> multibytetowidechar (cp_utf8, 0, STR, str. getlength (), pwchar, nlen1); </P> <p> char * pchar = NULL; <br/> dwordnlen2; </P> <p> nlen2 = widechartomultibyte (cp_acp, 0, pwchar, nlen1, pchar, 0, null, null ); <br/> pchar = new char [nlen2 + 1]; <br/> memset (PC Har, 0, nlen2 + 1); <br/> widechartomultibyte (cp_acp, 0, pwchar, nlen1, pchar, nlen2, null, null ); </P> <p> // search for information returned by the server upon logon <br/> Str. format ("% s", pchar); <br/> If (Str. find ("secure exit", 0) >=1) <br/>{< br/> MessageBox ("email login successful! "," Prompt "); <br/> m_ctruser.setfocus (); <br/>}< br/> else <br/> {<br/> MessageBox ("email logon failed! "," Prompt ", mb_iconerror | mb_ OK); <br/> m_ctruser.setfocus (); <br/>}</P> <p> // Delete temporary files and release memory <br/> deletefile ("recvdata. TMP "); <br/> Delete pchar; <br/> Delete pwchar; <br/>}

 

5. Source Code

Http://download.csdn.net/source/1747851

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.