Возможно, может помочь следующее - поскольку конечной точкой является https, в функции запроса curl должны быть установлены дополнительные параметры для работы с SSL.Функция curl, приведенная ниже, является упрощенной версией того, что я часто использую
<code><?php
/* /9412499/nevozmozhno-poluchit-otvet-json-ot-api-s-pomoschy-curl-v-php */
/* jsonplaceholder.typicode.com api experiments */
if( isset( $_GET['todoid'] ) ){
$id=filter_input( INPUT_GET, 'todoid', FILTER_SANITIZE_NUMBER_INT );
/* utility to quickly display data in readable fashion */
function pre( $data=false, $header=false, $tag='h1' ){
if( $data ){
$title = $header ? sprintf('<'.$tag.'>%s</'.$tag.'>',$header) : '';
printf('%s<pre>%s
', $ title, print_r ($ data, 1));}} / * основной помощник запроса curl * / function curl ($ url) {/ * установить соответствующий путь к ВАШЕМ файлу cacert.pem * / $ cacert = 'c: /wwwroot/cacert.pem';$ Завиток = curl_init ();if (parse_url ($ url, PHP_URL_SCHEME) == 'https') {curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, true);curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, 2);curl_setopt ($ curl, CURLOPT_CAINFO, $ cacert);} curl_setopt ($ curl, CURLOPT_URL, trim ($ url));curl_setopt ($ curl, CURLOPT_AUTOREFERER, true);curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, true);curl_setopt ($ curl, CURLOPT_FAILONERROR, true);curl_setopt ($ curl, CURLOPT_HEADER, false);curl_setopt ($ curl, CURLINFO_HEADER_OUT, false);curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true);curl_setopt ($ curl, CURLOPT_USERAGENT, 'Mozilla / 5.0 (Windows NT 6.1; Win64; x64) AppleWebKit / 537.36 (KHTML, как Gecko) Chrome / 58.0.3029.110 Safari / 537.36');curl_setopt ($ curl, CURLOPT_MAXREDIRS, 10);curl_setopt ($ curl, CURLOPT_ENCODING, '');$ res = (object) array ('response' => curl_exec ($ curl), 'info' => (object) curl_getinfo ($ curl), 'errors' => curl_error ($ curl));curl_close ($ curl);вернуть $ res;} function callapi ($ id) {$ url = sprintf ('
https://jsonplaceholder.typicode.com/todos/%s',$id);вернуть curl ($ url);} / * вызвать API * / $ res = callapi ($ id);/ * обрабатывать данные ответа * / if ($ res && $ res-> info-> http_code == 200) {/ * для отладки * / pre ($ res-> response, 'Response data');/ * live * / #exit ($ res-> response);}}?>
Пример вывода:
Данные ответа
{
"userId": 2,
"id": 23,
"title": "et itaque necessitatibus maxime molestiae qui quas velit",
"completed": false
}