一、正常 curl 获取响应结果
1)、curl请求代码
$url = 'http:://www.baidu.com';
$data = ['param' => 'test'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type:application/json"));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
2)、curl_getinfo() 获取响应详情
...
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);
curl_close($ch);
二、获取发送的请求 header 信息
1)、代码
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
$error = curl_error($ch);
curl_close($ch);