簡而言之:捲曲overwritting內容類型,我設置GCM呼叫
內容類型,我同時使捲曲被覆蓋設置。以下培訓相關代碼:
詳細
我開發的笨移動應用後端應用程序,它需要做出GCM電話。 出於同樣的,我使用的,https://github.com/antongorodezkiy/codeigniter-gcm的笨-GCM庫。儘管它在我的本地機器上運行良好,但它會在我的服務器上返回錯誤。
在我正在我發現,正在使捲曲時所設置的內容類型被覆蓋的請求的檢查。所設置的內容類型是application/JSON而使得服務器的請求時,由於某種原因,它被過度寫入text/html的通過輸出請求的頭部就是明證。 這是使用的相關代碼。
$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);
但是請注意輸出,當我輸出$這個 - > 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
(
)
爲什麼捲曲改變內容類型?我怎樣才能確保它沒有改變? 任何幫助,將不勝感激。 謝謝!
編輯 我試着在PHP curl changes the Content-Type to application/x-www-form-urlencoded. Shouldn't do that提到的解決方案,但同樣被覆蓋
服務器響應通常是application/json。根據我讀的它也支持文本/純文本。但即使當我將Content-Type設置爲並且設置Accept標頭時,curl也會將發送內容類型更改爲text/html。 – arunondeck
你如何看到請求標題?嘗試[這種方式](http://stackoverflow.com/questions/866946/how-can-i-see-the-request-headers-made-by-curl-when-sending-a-request-to-the- ser)(第二個答案)將請求標頭寫入文件。 – umka