Answer the question
In order to leave comments, you need to log in
How to execute cURL request in PHP?
Tell me how to execute this cURL request in PHP:
curl -u testclient:testpass http://api.pleer.com/token.php -d 'grant_type=client_credentials'
$client_credentials = "testclient:testpass";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://api.pleer.com/token.php");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, $client_credentials);
$return = curl_exec($curl);
curl_close($curl);
print_r($return);
Answer the question
In order to leave comments, you need to log in
Google knows everything
// set POST variables
$url = 'http://api.pleer.com/token.php';
$userpwd = 'testclient:testpass '; // заменить на свои данные
$fields = array(
'grant_type' => 'client_credentials'
);
// url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
$result = curl_exec($ch);
curl_close($ch);
print_r('<pre>' . $result . '</pre>');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question