curl-library
Can't set headers using CURLOPT_HTTPHEADER
Date: Mon, 23 Jan 2012 20:31:45 +0400
Hi folks!
There is a problem I need your help with.
I'm trying to make a POST request to server, with content-type: text/xml.
However, it seems the command is ignored - I get the default "application/x-www-form-urlencoded" content type.
Could U please help me with this issue ?
Here is the code:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(!curl)
{
cout << "Shit happened!\n";
return 1;
}
res = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
res = curl_easy_setopt(curl, CURLOPT_URL, "http://www.livejournal.com");
res = curl_easy_setopt(curl, CURLOPT_POST, 1);
curl_slist *headers=NULL; // init to NULL is important
curl_slist_append(headers, "Accept: text/xml");
curl_slist_append(headers, "Content-Type: text/xml");
//curl_slist_append(headers, "charsets: utf-8");
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
//res = curl_easy_setopt(curl, CURLOPT_HEADER, 0);
//curl_setopt(curl, CURLOPT_RETURN, 1);
res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
string request = getRequest();
char* buf = new char[request.size()];
strcpy(buf, request.c_str());
res = curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf);
res = curl_easy_perform(curl);
curl_slist_free_all(headers);
delete[] buf;
curl_easy_cleanup(curl);
Here is the output:
* About to connect() to www.livejournal.com port 80 (#0)
* Trying 209.200.154.225... * connected
> POST / HTTP/1.1
Host: www.livejournal.com
Accept: */*
Content-Length: 472
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 472 out of 472 bytes
I've already tried to mix there curl options, setting headers before and after other commands - no success.
Thank you,
Andrey
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-01-23