PHP cURL not aible to show response - php

<?php
$ch = curl_init();
//$concept_id = $_POST['concept_id'];
curl_setopt($ch, CURLOPT_URL, "https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN/2022-03-31/concepts/84114007");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded'));
$response = curl_exec($ch);
//echo curl_error($ch);
//echo '<p>';
//echo curl_errno($ch);
//echo '<p>';
$info = rawurldecode(var_export(curl_getinfo($ch),true));
curl_close($ch);
echo "<pre>\n$info<br>\n</pre>";
var_dump ($response);
?>
I am not able to retrieve the response of the SNOMED API. Works with my browser with the same URL.
I received no error message, just an empty response.
Tried to add these parameters without change :
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Here the response:
array (
'url' => 'https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN/2022-03-31/concepts/84114007',
'content_type' => NULL,
'http_code' => 423,
'header_size' => 112,
'request_size' => 123,
'filetime' => -1,
'ssl_verify_result' => 0,
'redirect_count' => 0,
'total_time' => 0.61424600000000007,
'namelookup_time' => 0.052975000000000001,
'connect_time' => 0.15305099999999999,
'pretransfer_time' => 0.51591100000000001,
'size_upload' => 0.0,
'size_download' => 0.0,
'speed_download' => 0.0,
'speed_upload' => 0.0,
'download_content_length' => 0.0,
'upload_content_length' => 0.0,
'starttransfer_time' => 0.61422100000000002,
'redirect_time' => 0.0,
'redirect_url' => '',
'primary_ip' => '3.225.65.37',
'certinfo' =>
array (
),
'primary_port' => 443,
'local_ip' => '10.102.1.146',
'local_port' => 41662,
)
string(0) ""

When we look for information on the 423 code returned, we see that sometimes pages are blocked because the client is not an Internet browser
So if we simulate an internet explorer with the "Agent" parameter, it works
Normally the code below should help you
// Determinate URL
$urlTest = "https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN/2022-03-31/concepts/84114007";
// Initialization Session CURL
$curlObject = #curl_init();
// Simulation of Agent
$config['useragent'] = 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0';
// Définition Options de la Session CURL
curl_setopt($curlObject, CURLOPT_USERAGENT, $config['useragent']);
curl_setopt($curlObject, CURLOPT_VERBOSE, false);
curl_setopt($curlObject, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlObject, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObject, CURLOPT_CONNECTTIMEOUT, 600);
curl_setopt($curlObject, CURLOPT_URL,$urlTest);
// Running Session CURL
$curlResponse = #curl_exec($curlObject);
// If successful execution
if($curlResponse!=false)
{
$dataList = json_decode($curlResponse, true); echo "<pre>"; print_r($dataList); echo "</pre>";
}
else echo "Error Connexion CURL - [".curl_errno($curlObject)."] ".curl_error($curlObject);

Related

Unexpected 401 response when calling haveibeenpwned API

I dead stuck on an 401 response, another user suggested my header didn't included a leading white space for the API key field. I corrected it and am still receiving a 401. The API key should work, I paid for it last night, and regenerated a new one multiple times
my code:
<?php
$service_url = 'https://haveibeenpwned.com/api/v3/breachedaccount/?account=emailtest123#gmail.com';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$ch = curl_init ($service_url);
curl_setopt ($ch, CURLOPT_HTTPGET, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'hibp-api-key: 8bcxxxxxxxxxxxxxx1bc11',
'user-agent: FAUstudentproject'
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$returndata = curl_exec ($ch);
$status_code = #curl_getinfo($ch, CURLINFO_HTTP_CODE);
print_r($status_code);
print_r($returndata);
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
$json = curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded1 = json_decode($curl_response,true);
if (isset($decoded1->response->status) && $decoded1->response->status == 'ERROR') {
echo "hello";
echo curl_getinfo($ch);
die('error occured: ' . $decoded1->response->errormessage);
}
echo 'response ok!';
print_r(json_decode($json));
var_export($decoded1->response);
?>
The response:
401{ "statusCode": 401, "message": "Access denied due to missing hibp-api-key." }array ( 'url' => 'https://haveibeenpwned.com/api/v3/breachedaccount/?account=emailtest123#gmail.com', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 20, 'redirect_count' => 0, 'total_time' => 0.04700000000000000011102230246251565404236316680908203125, 'namelookup_time' => 0.01600000000000000033306690738754696212708950042724609375, 'connect_time' => 0.0309999999999999997779553950749686919152736663818359375, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '2606:4700::6812:ad0d', 'certinfo' => array ( ), 'primary_port' => 443, 'local_ip' => '2601xxxxxxxxxxxxxxxxx21d3', 'local_port' => 59096, 'http_version' => 0, 'protocol' => 2, 'ssl_verifyresult' => 0, 'scheme' => 'HTTPS', )error occured during curl exec. Additioanl info:
You are using the wrong variable: replace curl_setopt($curl, CURLOPT_HTTPHEADER with curl_setopt($ch, CURLOPT_HTTPHEADER. You're using curl_init twice in your code.
Check your code to fix it, using only $ch or $curl, not both.

PHP cURL is not working on Xampp Windows 10

I am using curl to fetch data from different web service hosted on different location on the web. I am trying to fetch the data to my localhost.
$token1="SOMETOKENXX";
$mobileNumber= $_POST['number'];
$postData = array(
'mobile' =>$mobileNumber
);
$service_url ='http://api.hashtagloyalty.in/merchants/users/users_profile';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $service_url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_PORT, 8080);
curl_setopt($curl, CURLOPT_USERAGENT , "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17");
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json','Authorization:'.$token1));
$curl_response = curl_exec($curl);
// echo($curl_response);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}else{
echo "TRUE";
}
curl_close($curl);
I am not able to fetch the result on xampp localhost but working on GoDaddy live server.
I am working on latest version of xampp 7.2.6 and Windows 10 OS
I am accessing my localhost on port 8080 means my localhots url is localhost:8080 .
How can I know if something is blocking my request?
There is no result and giving empty result.
Please help
error
array ( 'url' => 'http://api.hashtagloyalty.in/merchants/users/users_profile', 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 20.204, 'namelookup_time' => 1.0E-6, 'connect_time' => 0.0, 'pretransfer_time' => 0.0, 'size_upload' => 0.0, 'size_download' => 0.0, 'speed_download' => 0.0, 'speed_upload' => 0.0, 'download_content_length' => -1.0, 'upload_content_length' => -1.0, 'starttransfer_time' => 0.0, 'redirect_time' => 0.0, 'redirect_url' => '', 'primary_ip' => '', 'certinfo' => array ( ), 'primary_port' => 0, 'local_ip' => '', 'local_port' => 0, )error occured during curl exec. Additioanl info:
Probably a firewall issue
cURL uses port 1080 which is probably not open
Several fixes:
Open port 1080 in your firewall/router
or
Specify a (working) port for cURL
curl_setopt($curl, CURLOPT_PORT, PortYouWantHere)
curl is not working because my organisation's proxy is blocking the request. So I have added the below code and it worked like charm :)
curl_setopt($ch, CURLOPT_PROXY, $proxyhostandpass);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyusernamepass);

Error on PHP cURL with POST Method [duplicate]

I want to extract data from this URL with Php Curl:
https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY
But I got the following error:
"{"errorType":"SERVER_ERROR","userErrorMessage":"Unexpected server error occurred. We apologize for the inconvenience. Please try again later.","errorMessage":"Exception occurred in server."}".
How I can extract the data from that link with php curl?
Here is my code
$url = 'https://api.traveloka.com/en/v2/flight/search/oneway';
$params = [
'context' => [
'tvLifetime' => 'eTq6r7InDN+j0vrg5Bujah9yFLWfBGsNGWxzjTBUa/jvVfn8fy/IF40U7OQl0vjmoqMJwuSocopqxISYLLi6YlngzuFViHSWhNHdFgs+49yydWXm5gSjBRwDBFuO0UKHd+B69Ip0Tk1qnKH+oyzW43f2GdS7QOd10yBpqoCOyOk73cVe4oyqCjYUR7X72PoHr14UQNQEUjl1NP5Mcxp+1Gw6RzKF7uV7jMRzmsYbGfGKpYLfsYtxaSx1t35KGWOO605YN9Mj2n5kP5fOD7j2KA9adtfLBtEymWXf6tEt3ug8oBVyzj5c2/pp/hboYilQnDRCih+RwhV5WX7hPTw9IsKapSNtWZ1NX8biH7UyYuhNLgcLK03OS4WNpoO+NphjOPKh09oBpUgrEJ0UqeY+1rfj98lWMAdpMO5rp2E5pvmP7HRuW6CqBwSchPLtVPQAi7ceDGYgYneH+AfodZMd5A==',
'tvSession' => '9tCFUug+5pqBk0WdAmwAbThaxD2lAm75JaxFJenJTB2MkEWW7bwVa5FW83NZnCLnlL2TAAijDDIDfD9YbC7NhRws3r5fKxPj62n1bJ+Nck309g3Rkogk+dtxsoMRpFHbkVkEJbYuNFbd9Ckp9iEBGg==',
'nonce' => '5eebdd23-2574-4465-afa7-cecc94b8f909'
],
'clientInterface' => 'desktop',
'data' => [
'currency' => 'IDR',
'destinationAirportOrArea' => 'DPS',
'flightDate' => [
'day' => '14',
'month' => '10',
'year' => '2017'
],
'isReschedule' => 'false',
'locale' => 'en_ID',
'newResult' => 'true',
'numSeats' => [
'numAdults' => '1',
'numChildren' => '0',
'numInfants' => '0'
],
'seatPublishedClass' => 'ECONOMY',
'seqNo' => 'null',
'sortFilter' => [
'filterAirlines' => [],
'filterArrive' => [],
'filterDepart' => [],
'filterTransit' => [],
'selectedDeparture' => '',
'sort' => 'null'
],
'sourceAirportOrArea' => 'JKTA',
'searchId' => 'null',
'usePromoFinder' => 'false',
'useDateFlow' => 'false'
],
'fields' => []
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_REFERER, "https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Host: api.traveloka.com",
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Language: en-us,en;q=0.5",
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Pragma: no-cache",
"Cache-Control: no-cache")
);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
Actually I'm not doing screen crawling, but I want to crawl its json data. I open the "Network" Tab in browser and see the XHR section, and then I want to grab the response from that XHR section. So how to do it and what's wrong with my code?
As per the URL you have given using the below code, you would get nothing rather the redirection link:
Replace with the link and parameters with the correct api:
General format of using CURL is given here:
$ch = curl_init();
$params = urldecode('{"ap":"' . 'JKTA.DPS' . '","dt":"' . '14-10-2017.NA' . '","ps":"' . '1.0.0'. '","sc":"' . 'ECONOMY'. '"}');
$url = 'https://www.traveloka.com/en/flight/fullsearch?JsonData=' . $params;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
if (!empty($output)) {
$x = json_decode($output, true);
var_dump($x);
}else{
return FALSE;
}
What you want to do is called Web scraping, there are plenty of tools that you can use to do that.
For now, go for:
https://github.com/FriendsOfPHP/Goutte
or https://github.com/duzun/hQuery.php.

Error on cURL with POST data

I want to extract data from this URL with Php Curl:
https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY
But I got the following error:
"{"errorType":"SERVER_ERROR","userErrorMessage":"Unexpected server error occurred. We apologize for the inconvenience. Please try again later.","errorMessage":"Exception occurred in server."}".
How I can extract the data from that link with php curl?
Here is my code
$url = 'https://api.traveloka.com/en/v2/flight/search/oneway';
$params = [
'context' => [
'tvLifetime' => 'eTq6r7InDN+j0vrg5Bujah9yFLWfBGsNGWxzjTBUa/jvVfn8fy/IF40U7OQl0vjmoqMJwuSocopqxISYLLi6YlngzuFViHSWhNHdFgs+49yydWXm5gSjBRwDBFuO0UKHd+B69Ip0Tk1qnKH+oyzW43f2GdS7QOd10yBpqoCOyOk73cVe4oyqCjYUR7X72PoHr14UQNQEUjl1NP5Mcxp+1Gw6RzKF7uV7jMRzmsYbGfGKpYLfsYtxaSx1t35KGWOO605YN9Mj2n5kP5fOD7j2KA9adtfLBtEymWXf6tEt3ug8oBVyzj5c2/pp/hboYilQnDRCih+RwhV5WX7hPTw9IsKapSNtWZ1NX8biH7UyYuhNLgcLK03OS4WNpoO+NphjOPKh09oBpUgrEJ0UqeY+1rfj98lWMAdpMO5rp2E5pvmP7HRuW6CqBwSchPLtVPQAi7ceDGYgYneH+AfodZMd5A==',
'tvSession' => '9tCFUug+5pqBk0WdAmwAbThaxD2lAm75JaxFJenJTB2MkEWW7bwVa5FW83NZnCLnlL2TAAijDDIDfD9YbC7NhRws3r5fKxPj62n1bJ+Nck309g3Rkogk+dtxsoMRpFHbkVkEJbYuNFbd9Ckp9iEBGg==',
'nonce' => '5eebdd23-2574-4465-afa7-cecc94b8f909'
],
'clientInterface' => 'desktop',
'data' => [
'currency' => 'IDR',
'destinationAirportOrArea' => 'DPS',
'flightDate' => [
'day' => '14',
'month' => '10',
'year' => '2017'
],
'isReschedule' => 'false',
'locale' => 'en_ID',
'newResult' => 'true',
'numSeats' => [
'numAdults' => '1',
'numChildren' => '0',
'numInfants' => '0'
],
'seatPublishedClass' => 'ECONOMY',
'seqNo' => 'null',
'sortFilter' => [
'filterAirlines' => [],
'filterArrive' => [],
'filterDepart' => [],
'filterTransit' => [],
'selectedDeparture' => '',
'sort' => 'null'
],
'sourceAirportOrArea' => 'JKTA',
'searchId' => 'null',
'usePromoFinder' => 'false',
'useDateFlow' => 'false'
],
'fields' => []
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_REFERER, "https://www.traveloka.com/en/flight/fullsearch?ap=JKTA.DPS&dt=14-10-2017.NA&ps=1.0.0&sc=ECONOMY");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Host: api.traveloka.com",
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Language: en-us,en;q=0.5",
"X-Requested-With: XMLHttpRequest",
"Connection: keep-alive",
"Pragma: no-cache",
"Cache-Control: no-cache")
);
$result = curl_exec($ch);
print_r($result);
curl_close($ch);
Actually I'm not doing screen crawling, but I want to crawl its json data. I open the "Network" Tab in browser and see the XHR section, and then I want to grab the response from that XHR section. So how to do it and what's wrong with my code?
As per the URL you have given using the below code, you would get nothing rather the redirection link:
Replace with the link and parameters with the correct api:
General format of using CURL is given here:
$ch = curl_init();
$params = urldecode('{"ap":"' . 'JKTA.DPS' . '","dt":"' . '14-10-2017.NA' . '","ps":"' . '1.0.0'. '","sc":"' . 'ECONOMY'. '"}');
$url = 'https://www.traveloka.com/en/flight/fullsearch?JsonData=' . $params;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
if (!empty($output)) {
$x = json_decode($output, true);
var_dump($x);
}else{
return FALSE;
}
What you want to do is called Web scraping, there are plenty of tools that you can use to do that.
For now, go for:
https://github.com/FriendsOfPHP/Goutte
or https://github.com/duzun/hQuery.php.

Freebase API works in browser but not in PHP

This question is similar to: Freebase API call works in browser but fails with curl but no answers there.
I have this URL that works in the browser:
https://www.googleapis.com/freebase/v1/search?query=Cee+Lo+Green&filter=%28all+type%3A%2Fmusic%2Fartist+created%3A%22The+Lady+Killer%22%29&limit=10&key=my_key_here
Returns:
{"status":"200 OK","result":[{"mid":"/m/01w5jwb","id":"/en/cee_lo_1974","name":"Cee Lo Green","notable":{"name":"Singer-songwriter","id":"/m/016z4k"},"lang":"en","score":814.733643}],"cost":6,"hits":2}
However, in PHP, the following code doesn't work:
<?php
namespace com\voting;
class Freebase{
public function query(){
$service_url = 'https://www.googleapis.com/freebase/v1/search';
$params = array(
'query' => 'Cee Lo Green',
'filter' => '(all type:/music/artist created:"The Lady Killer")',
'limit' => 10,
'key' => API_KEY );
$url = $service_url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response;
}
}
?>
A dump of curl, gives this:
array (size=22)
'url' => string 'https://www.googleapis.com/freebase/v1/search?query=Cee+Lo+Green&filter=%28all+type%3A%2Fmusic%2Fartist+created%3A%22The+Lady+Killer%22%29&limit=10&key=my_key_here' (length=191)
'content_type' => null
'http_code' => int 0
'header_size' => int 0
'request_size' => int 0
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.047
'namelookup_time' => float 0
'connect_time' => float 0.063
'pretransfer_time' => float 0
'size_upload' => float 0
'size_download' => float 0
'speed_download' => float 0
'speed_upload' => float 0
'download_content_length' => float -1
'upload_content_length' => float -1
'starttransfer_time' => float 0
'redirect_time' => float 0
'certinfo' =>
array (size=0)
empty
'redirect_url' => string '' (length=0)
I thought maybe a connectivity issue, but I tried a regular http URL and curl showed that it was able to get the content of the page.
Update 1
I should have done my homework before posting. With Wireshark, I can see the following text:
Alert Message
Level: Fatal (2)
Description: Unknown CA (48)
Is my setup improperly configured?
Thanks, in just a script:
<?php
$service_url = 'https://www.googleapis.com/freebase/v1/search';
$params = array(
'query' => 'Cee Lo Green',
'filter' => '(all type:/music/artist created:"The Lady Killer")',
'limit' => 10,
'key' => API_KEY );
$url = $service_url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//WARNING: this would prevent curl from detecting a 'man in the middle' attack
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response;
?>
This answer solved it for me:
HTTPS and SSL3_GET_SERVER_CERTIFICATE:certificate verify failed, CA is OK
Final solution:
<?php
namespace com\voting;
class Freebase{
public function query(){
$service_url = 'https://www.googleapis.com/freebase/v1/search';
$params = array(
'query' => 'Cee Lo Green',
'filter' => '(all type:/music/artist created:"The Lady Killer")',
'limit' => 10,
'key' => API_KEY );
$url = $service_url . '?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//WARNING: this would prevent curl from detecting a 'man in the middle' attack
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return $response;
}
}
?>

Categories