未应用cURL标头

时间:2015-12-03 15:03:40

标签: php curl header content-type

我在PHP中有以下cURL语法:

$ch = curl_init();

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                                            'Content-Type: application/json',
                                            'Connection: Keep-Alive',
                                            'account:A004',
                                            'key : 1234-12'
                                            ));
        curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    $request=  curl_getinfo($ch);
    var_dump($request);

echo "<br><br><br>Reply:";
    $content = curl_exec($ch);

这部分工作,因为我从我的服务器得到一个结果,但没有发送正确的标头,所以服务器没有回复任何数据。输出是:

array(22) 
 {
   ["url"]=> string(94) "https://api.domain.com/v1/config/limits"
   ["content_type"]=> NULL
   ["http_code"]=> int(0)
   ["header_size"]=> int(0)
   ["request_size"]=> int(0) 
   ["filetime"]=> int(0) 
   ["ssl_verify_result"]=> int(0) 
   ["redirect_count"]=> int(0) 
   ["total_time"]=> float(0) 
   ["namelookup_time"]=> float(0) 
   ["connect_time"]=> float(0) 
   ["pretransfer_time"]=> float(0)
   ["size_upload"]=> float(0)
   ["size_download"]=> float(0)
   ["speed_download"]=> float(0)
   ["speed_upload"]=> float(0)
   ["download_content_length"]=> float(-1)
   ["upload_content_length"]=> float(-1)
   ["starttransfer_time"]=> float(0)
   ["redirect_time"]=> float(0)
   ["certinfo"]=> array(0) { }
   ["redirect_url"]=> string(0) ""
 } 

答复:

   HTTP/1.1 401 Unauthorized Server: nginx
   Date: Thu, 03 Dec 2015 14:46:26 GMT
   Content-Type: application/json; charset=utf-8
   Content-Length: 51
   Connection: keep-alive
   Access-Control-Allow-Origin: *

   {"status":"failure ","data":"Authentication Error"}

为什么标题没有设置为内容标题和键?

一如既往地谢谢。

1 个答案:

答案 0 :(得分:0)

这是一个简单的问题,令人沮丧。间距

只是标题上的格式。 'key:1234-12' 应该 'key:1234-12'

感谢您的时间。