我正在进行Post请求,为此我必须将标题内容类型设置为application/json
,因为我正在编写以下代码:
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Accept: application/json");
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "charsets: utf-8");
res = curl_easy_setopt(curl, CURLOPT_HEADER,headers);
但是当我编译程序时,错误正在以
的形式出现Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 22
Content-Type: application/x-www-form-urlencoded
请尽快帮助我将此内容类型设置为application/json
答案 0 :(得分:4)
您必须将标题放在......
CURLOPT_HTTPHEADER
...而...
CURLOPT_HEADER
...意味着在输出中包含标题
因此,您的解决方案可能只是将CURLOPT_HEADER
替换为CURLOPT_HTTPHEADER