An error using the CHttpFile

Source: Internet
Author: User

Put a part of the code first

CString strhttpname="http://localhost/TestReg/RegForm.aspx";//pages that need to submit dataCString Strformdata ="username=abc&password=123";//data that needs to be submittedCInternetSession Sess;
CHttpFile*FileGet;
CString strheaders= _t ("content-type:application/x-www-form-urlencoded");//Request Header Try{FileGet= (chttpfile*) Sess. OpenURL (Strhttpname);//Open File } Catch(cexception*e) {FileGet=0; Throw; } CString strsentence, Strgetsentence=""; if(fileGet) {DWORD dwstatus; DWORD Dwbufflen=sizeof(dwstatus); BOOL bsuccess= Fileget->queryinfo (http_query_status_code| Http_query_flag_number, &dwstatus, &Dwbufflen); if(Bsuccess && dwstatus>= $&&dwStatus< -) {
BOOL result = fileget->sendrequest (strheaders, (LPVOID) (LPCTSTR) Strformdata, Strformdata.getlength ());

while(Fileget->readstring (strsentence))//return results After reading the submitted data{strgetsentence= strgetsentence + strsentence +Char( -) +Char(Ten); } AfxMessageBox (Strgetsentence); //Show back Page content } Else{Strsentence.format ("post error, error code:%d", dwstatus); AfxMessageBox (strsentence); } FileGet-Close (); Delete FileGet; } ElseAfxMessageBox ("cannot find web file! "); Sess. Close ();

Because of the need to use post to crawl the content returned by a webpage, so found in MFC features are not so powerful chttpfile to do, also enough.

General network programming of the demo are ANSI character sets, also have no problem, the above code to change can use, get the Unicode project, will add _t identifier and do some character set conversion, soon can run, but the problem came, is sent to the request always can not make the server correctly accept, and return some errors, this debugging does not matter, 2 hours passed.

Finally, in the case of PHP program and MFC program, the problem is locked in the underlined code, the ANSI is sent Char characters, is not a problem, and in the Unicode case, the past is WCHAR characters, and compile without error, even in the Unicode version, This function is also expected to accept Char characters.

Well, the library function is written like this, it's gem enough.

An error using the CHttpFile

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.