我在PHP中使用cURL发送JSON请求。在验证错误上,我正在点击的API将返回400错误。如果我使用Chrome扩展程序Postman,我会看到整个状态,其代码如下所示:http://i.imgur.com/QMi5vX9.png
但是当我使用cURL发布时,这是我从curl_getinfo收到的:
(
[url] => https://**sensitive**/
[content_type] =>
[http_code] => 400
[header_size] => 157
[request_size] => 315
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.929666
[namelookup_time] => 0.000949
[connect_time] => 0.201551
[pretransfer_time] => 0.741269
[size_upload] => 173
[size_download] => 0
[speed_download] => 0
[speed_upload] => 186
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0.929631
[redirect_time] => 0
[certinfo] => Array
(
)
)
有没有办法从cURL获取整个状态消息?
答案 0 :(得分:1)
您可以从标题中获取整个http_code。
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);