lasan
lasan

Reputation: 365

How to get a response using cURL?

I'm trying to get a response using curl according to this doc. But I'm new to cURL/REST and don't have an idea how to do that.

For an example there is this code in the doc that says it returns a list of folders

curl -X GET -u "email:password" https://www.seedr.cc/rest/folder ,

but when I try it in PHP it doesn't work. how can I do this ->

Edit : it seems this is a command line curl . I tried it with command line and it works, but I need to know how to use this in a PHP script .

Upvotes: 1

Views: 539

Answers (2)

Kudehinbu Oluwaponle
Kudehinbu Oluwaponle

Reputation: 1145

This is an example of how to use cURL with php. You can use the curl_setopt function to set and change the options to suit your peculiar case. Some of them are actually optional. You can check the table here to get a full list of what they do

    $durl = "https://www.seedr.cc/rest/folder?email=$password" ;
    $ch =  curl_init()  ;
    curl_setopt($ch,CURLOPT_URL, $durl);
    curl_setopt ($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_FAILONERROR, 1);
    $dinf = curl_exec ($ch); 
    if(!curl_errno($ch) ){
        echo $dinf ;

    }else{
        echo curl_error($ch) ;
    }

Upvotes: 1

Indent
Indent

Reputation: 4967

You don't need use curl. You can do it directly in php.

$url="https://www.seedr.cc/rest/folder"

$context = stream_context_create(array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$username:$password")
    )
));
$data = file_get_contents($url, false, $context);

Upvotes: 1

Related Questions