简体   繁体   中英

PHP cURL GET Request to REST API not returning anything

I'm trying to use the UMLS Search REST API . I successfully retrieved the TGT and The ST. However, when trying to do a search as mentioned in the documentations, I got no response at all. Here's my code:

<?php
$service_ticket='xxx' //ST retrieve earlier
$cURLConnection = curl_init();
curl_setopt($cURLConnection, CURLOPT_URL,"https://uts-ws.nlm.nih.gov/rest/search/current");
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
//avoid unable to get local issuer certificate
 $values = array(
    'ticket' => $service_ticket,
    'string' => 'C0162565'
    );
$params = http_build_query($values);
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $params); 
$qresult = curl_exec($cURLConnection);
curl_close($cURLConnection);
$jsonArrayResponse = json_decode($qresult,true);
print_r($jsonArrayResponse);
?>

The API expects a GET request, but using curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $params); is changing the request type to POST. removing this command and adding the parameters directly to the URL fixes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM