william23
V2EX  ›  API

api 接口访问,需要用 header 请求,可是返回为 false,求解

  •  
  •   william23 · May 11, 2016 · 2656 views
    This topic created in 3694 days ago, the information mentioned may be changed or developed.

    $url="api url"; $headers=array('Authorization:11',"X-API-KEY:22"); $ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HTTPGET, true); $file_contents = curl_exec($ch);//获得返回值 dump($file_contents); curl_close($ch); $file_contents 变量返回为 false

    6 replies    2016-05-11 17:23:48 +08:00
    Jaylee
        1
    Jaylee  
       May 11, 2016
    curl_error()
    william23
        2
    william23  
    OP
       May 11, 2016
    奇怪,代码怎么乱了,一楼献上整理过后的代码
    $url="api url";
    $headers=array('Authorization:11',"X-API-KEY:22");
    $ch = curl_init();
    $timeout = 5;
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    $file_contents = curl_exec($ch);//获得返回值
    dump($file_contents);
    curl_close($ch);
    william23
        3
    william23  
    OP
       May 11, 2016
    curl_error() 返回值是 60
    william23
        4
    william23  
    OP
       May 11, 2016
    @Jaylee curl_error() 返回值是 60
    Jaylee
        5
    Jaylee  
       May 11, 2016
    @william23 是 curl_error 不是 curl_errno


    RTFM
    william23
        6
    william23  
    OP
       May 11, 2016
    @Jaylee 不好意思,

    SSL certificate problem: self signed certificate in certificate chain

    Thanks
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4055 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 05:16 · PVG 13:16 · LAX 22:16 · JFK 01:16
    ♥ Do have faith in what you're doing.