问题:
Is there any way to get both headers and body for a cURL request using PHP?有没有办法使用 PHP 获取 cURL 请求的标头和正文? I found that this option:我发现这个选项:
curl_setopt($ch, CURLOPT_HEADER, true);
is going to return the body plus headers , but then I need to parse it to get the body.将返回body 和 headers ,但随后我需要解析它以获取正文。 Is there any way to get both in a more usable (and secure) way?有没有办法以更可用(和安全)的方式获得两者?
Note that for "single request" I mean avoiding issuing a HEAD request prior of GET/POST.请注意,对于“单个请求”,我的意思是避免在 GET/POST 之前发出 HEAD 请求。
解决方案:
参考一: https://stackoom.com/question/cWxm参考二: Can PHP cURL retrieve response headers AND body in a single request?