<?php
$request = new HttpRequest();
$request->setUrl('https://api.backand.com/token');
$request->setMethod(HTTP_METH_POST);
$request->setHeaders(array(
'cache-control' => 'no-cache',
'content-type' => 'application/x-www-form-urlencoded',
'accept' => 'Accept:application/json'
));
$request->setContentType('application/x-www-form-urlencoded');
$request->setPostFields(array(
'username' => ‘user@mellanox.com',
'password' => ‘XXX',
'grant_type' => 'password',
'appName' => 'mellanoxstart'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.backand.com/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "username=user%40mellanox.com&password=XXX&grant_type=password&appName=mellanoxstart",
CURLOPT_HTTPHEADER => array(
"accept: Accept:application/json",
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}