int CHttpFetch::Post(const CString& strURL, const CString& strContent, CString& strResponse)
{
int nStatus = 200;
try
{
http::client::request request(StringUtility::CStr2Stl(strURL));
std::string content = StringUtility::CStr2Stl(strContent);
CString strContentLength;
strContentLength.Format(_T("%d"), content.length());
request << header("Content-Length", StringUtility::CStr2Stl(strContentLength));
request << header("Content-Type", "application/x-www-form-urlencoded");
request << body(content);
http::client::response response = m_client.post(request);
strResponse = StringUtility::Stl2CStr(chunked_body(response));
nStatus = status(response);
}
catch (std::exception& e)
{
UNREFERENCED_PARAMETER(e);
nStatus = 500;
}
return nStatus;
}
[cpp-netlib]如何发送post请求
最新推荐文章于 2023-08-23 23:20:29 发布