Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Headers flags option in libcurl library in C

Tags:

c

libcurl

I am doing Post request and for that I have to set header content type as application/json for that I am writing the following code:

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);

but when I compile the program the error is comming as

Accept: */*
Proxy-Connection: Keep-Alive
Content-Length: 22
Content-Type: application/x-www-form-urlencoded

Please help me out to set this Content type as application/json as soon as possible

like image 924
iDevAmit Avatar asked Oct 23 '25 21:10

iDevAmit


1 Answers

you must place your headers with...

CURLOPT_HTTPHEADER

...while...

CURLOPT_HEADER

...is meant to include the headers in the output

So your solution could be just replace CURLOPT_HEADER with CURLOPT_HTTPHEADER

like image 179
Davide Berra Avatar answered Oct 25 '25 10:10

Davide Berra