POST request trying to make a Session authentication in the REST SERVER return a HTML error 406 Not acceptable
Question
I have a REST server in drupal working. I get data if I go to the server endpoint.
In Navigator:
http://localhost/drupal-7.19/restserver/user/
Work fine.
I have created a PHP to make the Session authentication:
<?php
// REST Server URL
/*
* Server REST - user.login
*/
// REST Server URL
$request_url = "http://localhost/drupal-7.19/restserver/user/login";
// User data
$user_data = array(
"username" => "test",
"password" => "test",
);
$user_data = http_build_query($user_data);
// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/json")); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $user_data); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE); // Ask to not return Header
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);
$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Check if login was successful
if ($http_code == 200) {
// Convert json response as array
$logged_user = json_decode($response);
}
else {
// Get error msg
$http_message = curl_error($curl);
die($http_message);
}
echo "END php \n";
?>
But I getting this error:
TestAuth.php The requested URL returned error: 406
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange