drevls8138 2018-09-24 23:21
浏览 230

PHP curl_getinfo()在GET请求上为空

I am doing a GET request to RIPE's API and not getting the HTTP status code or anything inside curl_getinfo($i).

$i=curl_init();

        curl_setopt_array($i,
            array(
                CURLOPT_URL=>'https://rest.db.ripe.net/search.json?query-string='.$this->storage->ip->current, 
                CURLOPT_HTTPHEADER=>array('Accept: application/json'),
                CURLOPT_RETURNTRANSFER=>true, 
                CURLOPT_ENCODING=>'UTF-8'
            )
        );

Am I doing something wrong?

array(26) {
  ["url"]=>
  string(61) "https://rest.db.ripe.net/search.json?query-string=XX.XXX.XXX.37"
  ["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)
  ["redirect_url"]=>
  string(0) ""
  ["primary_ip"]=>
  string(0) ""
  ["certinfo"]=>
  array(0) {
  }
  ["primary_port"]=>
  int(0)
  ["local_ip"]=>
  string(0) ""
  ["local_port"]=>
  int(0)
}
  • 写回答

1条回答 默认 最新

  • douyan6958 2018-09-24 23:54
    关注

    You should use curl_exec() and curl_close() after curl_setopt_array() , add this:

    // grab URL and pass it to the browser
    curl_exec($i);
    
    // close cURL resource, and free up system resources
    curl_close($i);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类