POST request trying to make a Session authentication in the REST SERVER return a HTML error 406 Not acceptable 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:

&lt;?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" =&gt; "test",
  "password" =&gt; "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";

?&gt;


But I getting this error:

TestAuth.php The requested URL returned error: 406
First of all make sure you choose the appropriate Data types for request formatters and parsers for your resource. You will find it under admin/structure/services/list/your_resource_name/server. Having said that, this works for me :

// .xml asks for xml data in response, choose what you need here
$service_url = 'http://localhost/your-endpoint/user/login.xml'; 
$post_data = array(
    'username' =&gt; 'admin',
    'password' =&gt; 'pass',
);
// We format post data as application/x-www-form-urlencoded so make 
// sure that you tick it under the rest server parser options.
$post_data = http_build_query($post_data, '', '&amp;'); 
// Initialize the request
$curl = curl_init($service_url);
// We want curl to return a string
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);  
// Choose method POST
curl_setopt($curl, CURLOPT_POST, true);
// Feed the data to POST to curl
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); 
// Make it verbose for debugging.
curl_setopt($curl, CURLOPT_VERBOSE, true);
// Go!
$response = curl_exec($curl);
curl_close($curl);
print "LOGIN RESPONSE:\n";
var_dump($response);
// parse the response we get (in XML see above)...