I'm trying out HTTP Requests for the first time (also using PostMan). There, everything works fine. When exporting it with PHP cURL I get the following:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "htt..",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => array(
"Authorization: Basic ..."
),
));
$response = curl_exec($curl);
curl_close($curl);
I am expecting a Key in the response Header, So I'm trying to get the Response Header as a variable (pref. Array). How would I do this? I got no luck so far trying to use the following:
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
Thanks for any help in advance.
Edit 1:
Using https://incarnate.github.io/curl-to-php/ I converted the Postman cURL command to PHP cURL (instead of using Postman's generator) and got the following, which seems to work:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'htt..');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //manually added
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); //manually added
curl_setopt($ch, CURLOPT_HEADER, 1); //manually added
$headers = array();
$headers[] = 'Authorization: Basic ...';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
curl_close($ch);
echo $header;