[cpp-netlib]如何发送post请求
来源:互联网 发布:手机淘宝触屏版登陆 编辑:程序博客网 时间:2024/05/22 05:30
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;}