I made a PHP script to send HTTP requests on a website. Everything works "fine" when I don't set the header. The result is wrong though. But the program freezes when I change the headers. Here's my code:
$cookie_file_path='cookie';
$curl_connection = curl_init('http://www.website.com/path/to/script');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,"Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($curl_connection,CURLOPT_HTTPHEADER, array('Accept: application/json, text/javascript, */*; q=0.01','Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3','Accept-Encoding: gzip, deflate','Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7','Content-Type: application/json; charset=utf-8','X-Requested-With: XMLHttpRequest','Content-Length: 179','Pragma: no-cache','Cache-Control: no-cache'));
//I use the same header as the website
$post_data=array();
$post_data['address'] = 'my_address';
$post_data['lastname'] = 'my_lastname';
(...)
foreach ( $post_data as $key => $value)
$post_items[] = $key . '=' . $value;
$post_string = implode ('&', $post_items);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
file_put_contents('result.html',$result);
The main web page sends a POST request in AJAX to a script, and I'm trying to do the same with PHP. The script doesn't freeze when I comment out this line :
curl_setopt($curl_connection,CURLOPT_HTTPHEADER, array('Accept: application/json, text/javascript, */*; q=0.01','Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3','Accept-Encoding: gzip, deflate','Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7','Content-Type: application/json; charset=utf-8','X-Requested-With: XMLHttpRequest','Content-Length: 179','Pragma: no-cache','Cache-Control: no-cache'));
What are the possible reasons of this. Am I missing something?
Thanks