我正在使用下面的代码向 API 发布请求。出于调试目的:有没有办法回显此代码发送的完整请求(包括标头)?
$data = http_build_query($requests);
$url = parse_url($urlfull);
$host = $url['host'];
$path = $url['path'];
$fp = fsockopen('ssl://'.$host, 443, $errno, $errstr, 30);
if ($fp){
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Pragme: no-cache\r\n");
fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n\r\n");
fputs($fp, $data);
$result = '';
while(!feof($fp)) {
$result .= fgets($fp, 4096);
}
}
else {
$errors = array(
'status' => 'err',
'error' => "$errstr ($errno)"
);
}
fclose($fp);