下面的代码编译并打印响应。
我的问题是:作为代表对象的字符串的响应,如何将“res”转换为字符串或直接转换为 JSON 对象?
#include <stdio.h>
#include <curl/curl.h>
#include <json-c/json.h>
int main(int argc, char **argv) {
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080/system/genpass");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "length: 20");
headers = curl_slist_append(headers, "numbers: true");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
res = curl_easy_perform(curl);
printf("%u",res);
}
curl_easy_cleanup(curl);
}
Run Code Online (Sandbox Code Playgroud)