Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call curl in php?

I have try to call below command in using php but its give blank response so please anyone help to call below command in php.

curl -v -u [email]:[token] -X GET https://api.coolrunner.dk/v1/me
like image 319
ashish mulani Avatar asked Jan 27 '26 03:01

ashish mulani


1 Answers

You can use this curl class

  • php curl class

There is a sample :

include 'curl.class.php';

$curl = new Curl();

try {
    $respones = $curl->get('http://jsonplaceholder.typicode.com/posts/1');
    var_dump($respones);
    $result = json_decode($respones);
    echo "<br />Title : ".$result->title;
}catch (Exception $e){
    echo $e->getMessage();
    echo $curl->getError();
}

I think this is a sample for your request :

include 'curl.class.php';

$curl = new Curl();

$email = '[email protected]';
$token = 'kaiDklasdfSDFv6adsfvjhsadr';
try {
    $curl->setBasicAuth($email,$token);
    $respones = $curl->get('https://api.coolrunner.dk/v1/me');
    var_dump($respones);
}catch (Exception $e){
    echo $e->getMessage();
    echo $curl->getError();
}
like image 150
Amir Mohsen Avatar answered Jan 29 '26 15:01

Amir Mohsen