3

With PHP cURL library I have ability to operate with HTTP headers, but how about Connection header? When I'm sending any request, cURL always appends it with Connection: Keep-Alive and when I'm trying to modify this header to this one Connection: keep-alive (lowercase 'keep-alive'), it append instead, two lines as result:

Connection: Keep-Alive
Connection: keep-alive

How can I change it instead of append? Thanks.

UPDATE: I'm doing it in this way:

$url = 'http://some.host/path';
$ch = curl_init();
$hdrs = array(  'Host: some.host',
                'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0',
                'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'Accept-Language: en-US;q=0.5,en;q=0.3',
                'Accept-Encoding: gzip, deflate',
                'Connection: keep-alive');
curl_setopt($ch, CURLOPT_HTTPHEADER, $hdrs);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);            
curl_setopt($ch, CURLOPT_VERBOSE, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$data = curl_exec($ch);

UPDATE 1: Only solution I found (probably not the best) is to edit php_curl library file with hex editor.

3
  • Show your code. Commented Oct 29, 2016 at 19:06
  • How do you modify the header? Commented Oct 29, 2016 at 19:12
  • @developer my question is now updated with code example Commented Oct 29, 2016 at 19:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.