<?php
$URL="http://api.companieshouse.gov.uk/search/companies?q=Active&items_per_page=10&start_index=0";
$apikey = "My Key here";
$acceptTypes = [ "application/json" ]; // any types you support - not strictly necessary here
$headers = [ 'Accept:' . implode(', ', $acceptTypes) ];
$ch = curl_init();
//$headers = [ 'Accept:' . implode(', ', $acceptTypes) ];
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_URL => $URL,
// Our API key is the username - we need username:password
CURLOPT_USERPWD => $apikey . ":",
CURLOPT_HTTPHEADER => $headers,
// Make security explicit!
CURLOPT_SSL_VERIFYPEER => true, // default true per cURL 7.1
CURLOPT_SSL_VERIFYHOST => 2, // Should be the default e.g. secure.
CURLOPT_RETURNTRANSFER=>1,
CURLOPT_CUSTOMREQUEST=>"GET",
CURLOPT_FOLLOWLOCATION=>true,
CURLINFO_HEADER_OUT=> 1, // capture the header info
CURLOPT_VERBOSE=> 1, // turn verbose on
]);
$request = curl_exec($ch);
if (!curl_errno($ch)) {
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$resp_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo "http e code $http_code\n";
echo "Respons e code $resp_code\n";
$info = curl_getinfo($ch);
echo "<pre>" . print_r($info, true) . "</pre>";
//var_dump($request);
$decodedResult = json_decode($request);
echo "<pre>" . print_r($decodedResult, true) . "</pre>";
}
else {
echo curl_error($ch);
}
curl_close($ch);
?>
I keep getting Failed to connect to api.companieshouse.gov.uk port 80 after 95572 ms: Connection timed out. i am actually searching for Proposal to Strike Off
but if i change it $URL=“https://api.companieshouse.gov.uk/company/OC301540”;
it works perfectly … any thing i am doing wrong ?