libcurl 发送 post 请求,请求体为 json 格式
安装 libcurl
sudo apt install libcurl
使用 libcurl
使用 jsoncpp
创建 json 格式字符串,如果没有安装 jsoncpp
可以使用 apt install jsoncpp
安装
#define CURL_STATICLIB
#include <curl/curl.h>
#include <jsoncpp/json/json.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <chrono>
size_t ReceiveData(void *contents, size_t size, size_t nmemb, void *stream)
{
std::string *str = (std::string *)stream;
(*str).append((char *)contents, size * nmemb);
return size