In short:
The Content-type I am setting while making a curl is being overwritten. Relevent code below:
Detailed
I am developing a mobile app backend application in codeigniter which needs to make a gcm call. For the same I am using the codeigniter-gcm library from, https://github.com/antongorodezkiy/codeigniter-gcm. And though it works well on my local machine it returns error when put on my server.
Upon inspection of the request I was making I found that the content-type that is set when making the curl is being overwritten. The content-type that is set is application/json but for some reason when making the request on the server, it is being over written to text/html as evidenced by outputting the request headers. This is the relevant code used.
$headers[] = 'Content-Type:application/json';
$headers[] = 'Authorization:key='.$this->apiKey;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->apiSendAddress);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$this->responseData = curl_exec($curl);
$this->responseInfo = curl_getinfo($curl);
curl_close($curl);
But notice the output when I output $this->responseInfo
[url] => https://android.googleapis.com/gcm/send
[content_type] => text/html; charset=UTF-8
[http_code] => 401
[header_size] => 395
[request_size] => 967
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.052485
[namelookup_time] => 2.7E-5
[connect_time] => 0.002536
[pretransfer_time] => 0.010841
[size_upload] => 786
[size_download] => 147
[speed_download] => 2800
[speed_upload] => 14975
[download_content_length] => -1
[upload_content_length] => 786
[starttransfer_time] => 0.05244
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 2404:6800:4005:80a::200a
[certinfo] => Array
(
)
Why does curl change the Content-Type? How can I make sure it is not changed? Any help would be appreciated. Thanks!
EDIT I tried the solution mentioned in PHP curl changes the Content-Type to application/x-www-form-urlencoded. Shouldn't do that but that too is being overwritten