这段代码:
$headersSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$responseHeaders = substr($response, 0, $headersSize);
$responseBody = substr($response, $headersSize);
返回不正确的标题大小(strlen),例如这里:
...
Pragma: no-cache
Set-Cookie: foo=bar; pat
---- curl want split here ----
h=/
Access-Control-Allow-Origin: *
<!DOCTYPE html ...
响应可以有多个标头(重定向、继续等)。当然像这样是行不通的:
list($header, $body) = explode("\r\n\r\n", $response, 2);
如何正确确定标题的大小?