0

Currently, I'm working on a HTTP Proxy using libcurl in C++.

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

Above is my code to customize HTTP request header. The headers parameter is a curl_slist pointer variable. I have append all necessary heads information like Accept, Keep Alive, Referer and so on using curl_slist_append() method. However, when I used wireshark to observe the network traffic, I found that CURL didn't use my customized headers while it used "Accept: * / *\r\n".

Does anyone know how to disable the internal header of CURL?

Paul Peng
  • 31
  • 1
  • 5

2 Answers2

0

try CURLOPT_ENCODING, don't know about C++ but in PHP:

The contents of the "Accept-Encoding: " header. This enables decoding of the response. Supported encodings are "identity", "deflate", and "gzip". If an empty string, "", is set, a header containing all supported encoding types is sent.

chovy
  • 72,281
  • 52
  • 227
  • 295
  • Thanks to your reply. I knew CURLOPT_ENCODING, but it work for "Accept-Encoding:" header only. I used CURLOPT_COOKIE, CURLOPT_USERAGENT and CURLOPT_REFERER too. However, all of these option didn't cover all kinds of HTTP headers. Hence, I just need a general way to handle all kinds of HTTP headers. Personally, I think dump all headers into a curl_slist then pass to curl_easy_setopt() function is more efficient. – Paul Peng Sep 13 '12 at 08:10
  • Actually, I found some information in CURL documentation. But I really not sure about it. If you add a header that is otherwise generated and used by libcurl internally, your added one will be used instead. If you add a header with no content as in 'Accept:' (no data on the right side of the colon), the internally used header will get disabled. Thus, using this option you can add new headers, replace internal headers and remove internal headers. To add a header with no content, make the content be two quotes: "". – Paul Peng Sep 13 '12 at 08:16
  • I tested following code, but the result still the same. string test = "Accept:";curl_slist_append(headers, (char*)test.c_str()); – Paul Peng Sep 13 '12 at 08:18
  • [link](http://stackoverflow.com/questions/5707957/c-curl-json-rest), I think this is the best solution. – Paul Peng Sep 13 '12 at 09:48
  • Accept: application/json -- server is probably misconfigured if it serves json but doesn't accept this header. – chovy Sep 17 '12 at 02:25
0

CURLOPT_HTTPHEADER is the way to add, remove or replace internally used headers. If you have problems with this, show us a full program that repeats the problem and we might be able to help out.

Daniel Stenberg
  • 54,736
  • 17
  • 146
  • 222