当我用这段代码调用我的api时,我总是得到空的返回值,但它在我的Insomnia和我的shell上有效
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->body));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$return_data = curl_exec($ch);
curl_close($ch);
if ($return_data) return $return_data;
else return "empty";
我curl_getinfo返回:
[content_type] => text/html;charset=UTF-8
[http_code] => 500
[header_size] => 543
[request_size] => 164
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.269685
[namelookup_time] => 0.002741
[connect_time] => 0.024587
[pretransfer_time] => 0.157608
[size_upload] => 636
[size_download] => 0
[speed_download] => 0
[speed_upload] => 2364
[download_content_length] => -1
[upload_content_length] => 636
[starttransfer_time] => 0.157693
[redirect_time] => 0
1条答案
按热度按时间nkoocmlb1#
我解决了我问题,感谢能为cURL生成PHP代码的失眠症,
我把答案放在这里以防有人需要