user77115
user77115

Reputation: 5577

Why do I get a "HTTP Status 400 - Illegal Request Body" for this POST?

POST http://anyservice.com/my/servlet/interface/v1/book/events  
Content-Type: application/xml  
Accept: application/xml  
Authorization: Basic cXRE456ggz  

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CreateEvent>
  <serviceType>ABC</serviceType>
  <Version>2&#xD;</Version>
  <data>xyz</data>
</CreateEvent>

I'm guessing that CRLF i.e. #xD; is illegal in the middle of an HTTP BODY, but I can't find a reference in any RFC.

Why do I get a "HTTP Status 400 - Illegal Request Body" for this POST ?

Upvotes: 0

Views: 1553

Answers (1)

DaveRandom
DaveRandom

Reputation: 88647

This is not indicating that the request body is not compliant with HTTP, it is indicating that the request is not compliant with the application. Arguably 400 is the wrong response code in this situation, but at the same time I have been known to use it in this situation myself.

Really (IMHO) there should be a separate response code for use when the request does not comply with the overlying application, and 400 should be reserved for (as RFC2616 states) "malformed syntax" at the HTTP protocol level. But there isn't, so 400 makes the most sense.

My guess as to why it borks at your input is because you have an XML syntax error - the opening <CreateEvent> tag is missing it's closing >:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><CreateEvent<serviceType>ABC</serviceType>...
                                                                  ^^ Missing >

It's also possible that they don't like the carriage return, it which case just strip it out.

Upvotes: 1

Related Questions