php - GET 请求时 PHP 的 curl_getinfo() 为空
问题描述
我正在GET
向 RIPE 的 API 发出请求,但没有获得 HTTP 状态代码或内部的任何内容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'
)
);
难道我做错了什么?
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)
}
解决方案
您应该在 curl_setopt_array() 之后使用 curl_exec() 和 curl_close() ,添加以下内容:
// grab URL and pass it to the browser
curl_exec($i);
// close cURL resource, and free up system resources
curl_close($i);
推荐阅读
- python - SQL alchemy 为列添加表名前缀
- spring-boot - 如何使用 mockwebserver 模拟外部 API 的服务调用?我通过网络测试客户端调用我的控制器
- python - 如何在熊猫数据框中按日期范围选择列?
- rundeck - 如何使用徽标自定义 Rundeck?
- ansible - 运行 playbook 时强制使用 --limit 和 --tags
- json - 在大摇大摆的例子中描述属性
- flutter - 用于帐户设置的 Flutter DropDown 按钮
- ssl - NGINX 上的 SSL 证书无法加载
- spring-boot - 如何在 SpringBoot Server 项目中使用 Datatable?
- python - OpenCV VideoWriter 写入损坏的视频文件