2015-12-03 57 views
0

,我有以下卷曲语法在PHP中:卷曲头

$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); 

此工程部分,因为我从我的服务器得到一个结果,但正确的头的arent发送因此服务器不与任何答复数据。输出:

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

至少试着正确地格式化你的头文件:'account:[space] A004','key [nospacehere]:1234-12'。 –

+1

看起来很好。你是如何确定发送不发送的声明的?你倾销了这个请求吗? – arkascha

+0

谢谢@Mark,只是间隔 - 令人沮丧!谢谢。 – Smudger

回答

0

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

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

谢谢你的时间。