如何使用c++ /MFC http POST到web表单

how to http POST to a web form using C++ /MFC?

本文关键字:POST web 表单 http MFC 何使用 c++      更新时间:2023-10-16

我使用CInternetSession与GetHttpConnection,但我找不到任何关于如何填写和发布web表单的好信息。

这篇知识库文章解释了如何使用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());