How do I POST a buffer of JSON using libcurl?

后端 未结 4 1659
慢半拍i
慢半拍i 2021-02-02 15:08

My C++ program currently invokes curl through a pipe (popen(\"curl ...\")) to POST a file of JSON data to a web server. This has obvious performance limitations due

4条回答
  •  不知归路
    2021-02-02 15:29

    What about the required Content-Type header to match application/json just like the op is asking?

    Using the CURLOPT_POSTFIELDS from two answers above as well as CURLOPT_POST, the Content-Type automatically gets set to application/x-www-form-urlencoded.

    The only way for me to get the headers set correctly was to add what is outlined in this answer: JSON requests in C using libcurl

提交回复
热议问题