-1
<?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) ""
Azhar Khan
  • 3,829
  • 11
  • 26
  • 32
  • Please don't post [images of code](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question)! – brombeer Jan 30 '23 at 10:46
  • have you already changed the RETURNTRANSFER parameter to see what happens...? And yes, as @brombeer says, copy your code in your question, don't show screenshot – Juan Jan 30 '23 at 11:26
  • Yes I already tried every parameters combination :S – Guillaume Speierer Jan 30 '23 at 11:48
  • You have an http code 423. Have you looked for information on this return code...? – Juan Jan 30 '23 at 11:52
  • "HTTP/1.1 423 Server: nginx Date: Mon, 30 Jan 2023 11:51:49 GMT Content-Length: 0 Connection: keep-alive" that's what I received if I set the CURLOPT_HEADER to true. Don't know if it help – Guillaume Speierer Jan 30 '23 at 11:52
  • It said it's a "Locked" code. Can't found more information about this. Is that the code that the API Server send back ? – Guillaume Speierer Jan 30 '23 at 12:21

1 Answers1

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);
Juan
  • 690
  • 4
  • 15