3

我正在做发布请求,为此我必须设置标题内容类型,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请尽快帮我设置此内容类型

4

1 回答 1

4

你必须把你的标题...

CURLOPT_HTTPHEADER

...尽管...

CURLOPT_HEADER

...意味着在输出中包含标题

所以你的解决方案可能只是替换CURLOPT_HEADERCURLOPT_HTTPHEADER

于 2013-01-11T12:16:30.713 回答