c++中的CURL Post方法
CURL Post method in c++
假设我们有一个HTTP请求,如下所示:
POST /safebrowsing/downloads?client=Firefox&appver=3.0.8&pver=2.2&wrkey=AKEgNiux-3bBzAgJeFWgqbneh_GLc2OrmgXnpxPrdH1-hFpbAM8k1ovPA8GB_UMRueBHnL3QJ7gsdQOWVm6QJr_VZNgAm8jmLQ== HTTP/1.1
Host: safebrowsing.clients.google.com
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.8) Gecko/2009033100 Ubuntu/9.04 (jaunty) Firefox/3.0.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Content-Length: 120
Content-Type: text/plain
Cookie: PREF=ID=551a1b8848e36099:U=e6fa7464d7c48884:FF=0:TM=1327553284:LM=1345022478:S=Qd0IssyrqLi17a4s; NID=62=R9Y5bkQ5iLF8zlyhma1gnRBfxPDoWuG2FibC2wc5u0eAIQgAuo4WCXMeLhdPZ7FXJEpN2Sw1a6da6QUNP7OC5OqTYK0Y39vd6c2fUh4BhY2B5CGsKtHuQ5RCpSnefSkb
goog-malware-shavar;a:83372-91327:s:59904-95254:mac
goog-phish-shavar;a:227421-233955,235041-235401:s:107142-110470:mac
我已经构建了处理标头的代码部分。然而,消息正文部分我不知道该如何处理。我已经阅读了CURL示例代码,它们为HTTP表单POST提供了解决方案,而POST不是处理我的数据的方法。有人知道我应该使用什么参数来处理使用curl_easy_setopt()
函数的消息体吗?
FYI:cURL提供了一个非常方便的选项,列出了给定HTTP请求的特定选项:
--libcurl <file> Dump libcurl equivalent code of this command line
如果有疑问,您应该通过cURL(以及相应的选项,例如执行POST等)执行请求,同时使用此选项,因为它输出curl_easy_setopt
选项列表:
curl --libcurl out.c http://stackoverflow.com/ > /dev/null
然后在编辑器中打开out.c
文件:
...
curl_easy_setopt(hnd, CURLOPT_URL, "http://stackoverflow.com/");
curl_easy_setopt(hnd, CURLOPT_PROXY, NULL);
curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 0);
...
const char *post_data = "any_data";
...
curl_easy_setopt(curl_handle, CURLOPT_POST, 1);
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, post_data);
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 如何使用curlpp通过POST方法上传文件和json数据
- 使用 HTTP 方法 POST 或 PUT 上传数据
- boost::asio::strand post方法性能
- c++中的CURL Post方法
- CGI POST方法不起作用
- 如何在 C 或 C++ 中仅使用 GET 和 POST 方法编写 http 协议客户端
- c++ | Winsock -写HTTP Post上传文件的正确方法
- 如何在c++中通过post方法发送数据到php文件
- boost::io_service post方法是否引起新的分配?