When POSTing with Content-Type: application/xml and Content-Length: 0,
Services always returns the following error:

406 Not Acceptable:

The POST works with no Content-Type set or when set to application/json.
The error prevents the use of AngularJS $resource with Drupal REST endpoints that utilize POST with no content because AngularJS always sets the Content-Type header to application/xml.

It looks to me like RESTServer::parseXML is throwing an exception on processing NULL content, but I'm new to this stuff so I could be wrong.

Here's a capture of the HTTP conversation:

POST /rest/user/logout.json HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20100101 Firefox/17.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cookie: cookie-here
Content-Type: application/xml
Cache-Control: max-age=0, no-cache
Pragma: no-cache
Content-Length: 0

HTTP/1.1 406 Not Acceptable:
Date: Thu, 13 Dec 2012 02:28:42 GMT
Server: Apache
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0
ETag: "1355365722"
Last-Modified: Thu, 13 Dec 2012 02:28:42 GMT
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Headers: X-Requested-With, Content-Type
Access-Control-Allow-Methods: GET, HEAD, POST, PUT
Access-Control-Max-Age: 1728000
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 20
Keep-Alive: timeout=2, max=100
Connection: Keep-Alive
Content-Type: text/html

It's also worth noting that the error message ("406 Not Acceptable:") seems cut off and is a little uninformative.

Comments

marcingy’s picture

Status: Active » Closed (won't fix)

This does not seem like a bug with services, as a valid xml can't be Null it at least needs a tag.

droopey’s picture

Fair enough, but the error message is completely unexplanatory, and seems to be a bug in that is says "Not Acceptable:" - what is that colon for? What isn't acceptable?

Something like "Not Acceptable: malformed XML" whenever RESTServer::parseXML blows up would be a lot more useful.

revnoah’s picture

I'm dealing with a very similar issue at the moment, integrating AngularJS with Drupal Services. I'm able to log in, set the session cookie and add the CSRF token to the request headers. Editing content works as expected, respecting user permissions. However, when I try to log out, I get a 406 error, exactly as described. The session does not get cleared from the table in MySQL.

What did you do to resolve your problem?