Php 使用cURL返回代码的完整状态
我在PHP中使用cURL发送JSON请求。在一个验证错误中,我正在使用的API将返回一个400错误。如果我使用chrome extension Postman,我会看到整个状态,代码如下所示: 但是,当我发布使用cURL时,我从cURL_getinfo获得的信息如下:Php 使用cURL返回代码的完整状态,php,curl,Php,Curl,我在PHP中使用cURL发送JSON请求。在一个验证错误中,我正在使用的API将返回一个400错误。如果我使用chrome extension Postman,我会看到整个状态,代码如下所示: 但是,当我发布使用cURL时,我从cURL_getinfo获得的信息如下: ( [url] => https://**sensitive**/ [content_type] => [http_code] => 400 [header_size] =>
(
[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获取整个状态消息?您可以从标题获取整个http\U代码
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);