在 C++ 中使用 libcurl 设置 --data-binary

Setting --data-binary using libcurl in c++

我在 C++ 应用程序中使用来自 http://curl.haxx.se/ 的 curl api。我正在尝试编写相当于:

curl -v -X POST -H "Content-type: application/json; charset=utf-16" --data-binary @some data.json

我正在使用 curl_easy_setopt() 来设置各种选项,但我无法弄清楚的是 --data-binary 标志。我将使用哪个 CURLOPT 设置来设置它?

提前致谢

你应该使用 CURLOPT_POSTFIELDS:

specify data to POST to server [...] Pass a char * as parameter, pointing to the full data to send in a HTTP POST operation. You must make sure that the data is formatted the way you want the server to receive it.

注意:您可以使用 --libcurl 选项轻松发现这一点:

--libcurl FILE  Dump libcurl equivalent code of this command line