2011-12-19 30 views

回答

3

This knowledge base article說明如何使用CInternetSession來模擬POST請求。

附帶的範例代碼是這樣的:

CString strHeaders = _T("Content-Type: application/x-www-form-urlencoded"); 
// URL-encoded form variables - 
// name = "John Doe", userid = "hithere", other = "P&Q" 
CString strFormData = _T("name=John+Doe&userid=hithere&other=P%26Q"); 

CInternetSession session; 
CHttpConnection *pConnection = session.GetHttpConnection(_T("ServerNameHere")); 
CHttpFile *pFile = pConnection->OpenRequest(CHttpConnection::HTTP_VERB_POST, 
    _T("FormActionHere")); 
BOOL result = pFile->SendRequest(strHeaders, (LPVOID) (LPCTSTR) strFormData, 
    strFormData.GetLength()); 
+1

我怎麼能讀這是由Web服務器發回的效應初探頁? – 2011-12-22 03:41:08

+0

它將在'pFile'中可用。你可以使用它的Read()和ReadString()方法來提取它。 – 2011-12-22 08:47:35

+0

發佈後我得到返回代碼200這是好的,然後如果我讀取pFile我得到一個缺少的頁面結果 – 2011-12-22 14:48:56