C 使用CHttpFile實現Http請求

2021-07-09 02:55:08 字數 2768 閱讀 7173

c++實現http請求的**,參照網上的修改了下在mfc中使用

// 操作成功

#define success 0

// 操作失敗

#define failure 1

// 操作超時 www.it165.net

trymemset(cword, 0, num*sizeof(char)); //初始化

widechartomultibyte(cp_utf8, 0, strpostdata, -1, cword, num, null, null);

printf("content長度為%d\n", strlen(cword));

m_pfile->sendrequest(null, 0, cword, strlen(cword));//傳送請求

} else

dword dwret;

m_pfile->queryinfostatuscode(dwret);//查詢執行狀態

/*儲存http響應*/

char szchars[buffer_size + 1] = ;

string strrawresponse = "";

uint nreaded = 0;

while ((nreaded = m_pfile->read((void*)szchars, buffer_size)) > 0)

/*utf8轉unicode*/

int unicodelen = multibytetowidechar(cp_utf8, 0, strrawresponse.c_str(), -1, null, 0);

wchar *punicode = new wchar[unicodelen + 1];

memset(punicode, 0, (unicodelen + 1)*sizeof(wchar_t));

multibytetowidechar(cp_utf8, 0, strrawresponse.c_str(), -1, punicode, unicodelen);

strresponse = punicode;//最終響應結果

用CHttpFile實現簡單的GET POST資料

afxmessagebox 不能找到網頁檔案!sess.close 二 post 資料,比如用於上報,提交資訊等 cstring strhttpname http localhost testreg regform.aspx 需要提交資料的頁面 cstring strformdata usernam...

使用chttpfile的乙個錯誤

先貼一部分 需要提交資料的頁面 cstring strformdata username abc password 123 需要提交的資料 請求頭try catch cexception e cstring strsentence,strgetsentence if fileget afxmessa...

c語言的 h檔案使用小記

好久沒有使用c語言中的一些東西,都忘得差不多了。現在要完成乙個專案,其中我要提供相應的介面給別人,別人去實現,我直接呼叫。很容易想到的就是,他書寫乙個.h檔案,其中包含了相關的函式,我直接在包含.h檔案,我就可以直接呼叫相關函式了。上網查詢了相關寫法,h檔案大致如下 ifndef key h def...