Home > OS >  Curl in PHP just showing a blank page
Curl in PHP just showing a blank page

Time:04-23

I try to use curl to get a content, but any address always showing blank page. Everything works perfectly from reqbin.com.

Please, help me to find a solution...

<?php

$url = "https://api.airtable.com/v0/appTUTmrwscX1mD4y/Orders?maxRecords=3&view=Grid view";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$headers = array(
   "Authorization: Bearer HIDDEN_KEY",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);

?>

CodePudding user response:

i can't exactly figure out the problem with this as you have set the CURLOPT_RETURNTRANSFER to true, but maybe you could try using file_get_contents() instead, as this is the traditional way to get API data:

$options = array(
  'http'=> array(
    'method' => "GET",
    'header' => "Authorization: Bearer HIDDEN_KEY"
  )
);

$context = stream_context_create($options);

$data = file_get_contents('https://api.airtable.com/v0/appTUTmrwscX1mD4y/Orders?maxRecords=3&view=Grid view', false, $context);

CodePudding user response:

The trouble was with php-curl which was not installed to my server. After the installation the problem was solved. Thanks for replying.

  • Related