php - 无法在php中使用curl获取get api数据
问题描述
我有 python api url,它是一个获取请求。它以以下格式给出响应:
{"Status":"DONE"}
我curl
在 php 中使用来调用 api 并获取上面的 url,但没有显示任何内容。下面是代码:
<form action="test.php" method="post" enctype="multipart/form-data">
<input type="submit" name="testapi" value="Test API " />
</form>
<?php
if(isset($_POST['testapi']))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://<api_url>/api/v1/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
}
?>
请帮忙。谢谢
以下是添加后的回复 var_dump(curl_getinfo($ch));
G:\wamp\www\test.php:37:
array (size=26)
'url' => string 'https://<api_url>/api/v1/' (length=41)
'content_type' => null
'http_code' => int 0
'header_size' => int 0
'request_size' => int 0
'filetime' => int -1
'ssl_verify_result' => int 20
'redirect_count' => int 0
'total_time' => float 0.596189
'namelookup_time' => float 0.047973
'connect_time' => float 0.338623
'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 '' (length=0)
'primary_ip' => string '52.173.77.140' (length=13)
'certinfo' =>
array (size=0)
empty
'primary_port' => int 443
'local_ip' => string '192.168.0.102' (length=13)
'local_port' => int 52566
解决方案
推荐阅读
- javascript - 如何在表单转发器 jquery 上进行验证
- python - Found main Category based on sum groupby in pandas
- python - 在 Linux Ubuntu 18.04 上从 pip 安装 cartopy 时出现各种错误
- android - 在 Android 5.1 中启动 qt 5.15 应用程序(armv8a 构建)时崩溃
- php - 如何回显两个日期之间的所有日期?
- vbscript - How can I replicate programmatically in VBS what Word does when I insert a "built-in" property from the Insert->QuickPart->Document Property dropdown?
- c# - 优化 LINQ 查询
- maven - 如何为完整的源代码构建构建 Maven jar
- javascript - 如何删除空标签jquery的父级
- image - TYPO3 10 RTE ckeditor 图像