Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created December 13, 2022 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archie22is/fcc9d93f1bd1bffc0b3675451e21157f to your computer and use it in GitHub Desktop.
Save Archie22is/fcc9d93f1bd1bffc0b3675451e21157f to your computer and use it in GitHub Desktop.
Php CURL Test
<?php
///////////////////// TESTING VARS
//$endpoint = 'https://dev.admin.englishwoodlandstimber.co.uk/api/sale/stock-list';
//$secred = '46a4632d3d68173d2bea3dc684f82e70604704bf08817d6cb2fe959ca07768d8';
$ch = curl_init($endpoint);
$headers = [];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// this function is called by curl for each header received
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
}
);
$data = curl_exec($ch);
print_r($headers);
///////////////////// TESTING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment