I have a problem with login in a API Software with PHP cURL.
//define variable
$utentesl = ...
$passwordsl = ...
$Appkey = ...
header("CONTENT-TYPE: application/json;charset=utf-8");
header("Access-Control-Allow-Origin: *");
define('USER_AGENT', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.2309.372 Safari/537.36');
define('COOKIE_FILE', 'cookie.txt');
curl_setopt($ch, CURLOPT_URL, $paginalogin);
$accesso="Username=".$utentesl."&Password=". $passwordsl."&Appkey=".$appkey;
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
//login
curl_setopt($ch, CURLOPT_POSTFIELDS, $accesso);
//non funziona ma esiste: curl_setopt($ch, CURLOPT_USERPWD, $accesso);
//eseguo Login.
$login = curl_exec($ch);
$loginid = json_decode($login);
//stampo risultato se necessario
var_dump($loginid);
This code return:
object(stdClass)#2 (6) {
["StatusCode"]=>
string(20) "UnsupportedMediaType"
["ResponseCode"]=>
string(6) "02-001"
["ResponseId"]=>
int(1)
["ResponseIdDescription"]=>
string(21) "HttpResponseException"
["Message"]=>
string(22) "Unsupported Media Type"
["Details"]=>
NULL
}
I need to get from app a tocken ID.
I tried to insert various cURL variables (allow – origin: * , …) but still the same result.
If I add this code I get error:
"HTTP Error 400. The request is badly formed."
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json','charset: utf-8', 'Accept: application/json', 'Content-Length: 10000']);
2
Answers
I Add this code to fix error:
variables:
And Headers before curl_exec :
With no means of testing this particular API and not knowing the URL for the login endpoint might mean that the following is invalid but I hope that it might be useful.