<?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) ""
CodePudding user response:
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);