PHP cURL: Read specific response header information
P粉395056196
2023-08-06 16:06:37
<p>I'm using cURL in PHP to make a POST request to send data to a terminal that creates a resource. It returns a 201 response with a Location header which gives the URL of the resource created. I also get some information from the body of the response. <br /><br />How best to get the plain text body of the response, and get the value of the Location header? The curl_getinfo function fails to return information for this header when I try to do this: </p><p><br /></p>
<pre class="brush:php;toolbar:false;">curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) {
var_dump($header);
});</pre>
<p>I only see one header being output, which is the response code of "HTTP/1.1 201 Created". </p>