Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

json

libcurl

I'm using the curl api from http://curl.haxx.se/ in a c++ application. I'm trying to write the equivalent of:

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

I'm using curl_easy_setopt() to set up the various options but the bit I can't figure out is the --data-binary flag. Which CURLOPT setting would I use to set this?

Thanks in advance

like image 419
James Allan Avatar asked Jul 11 '26 15:07

James Allan


1 Answers

You should use 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.

Note: you can easily discover this by using the --libcurl option:

--libcurl FILE  Dump libcurl equivalent code of this command line
like image 187
deltheil Avatar answered Jul 14 '26 06:07

deltheil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!