Missing carriage return character '\r' in request body causes 400 Bad Request

I’ve been struggling with this for days and feel like I’m losing my mind. I’ve 2 identical requests 1 returns a 200 OK and the other returns a 400 Bad Request. I sniffed the requests in Postman console and discovered that the 200 request has Content-Length 1982 while the 400 request has Content-Length 2026.

I exported the collections associated with each request as JSON and figured that the 200 request body had \r\n as a line terminator while the 400 request body has \n as a terminator line. I presume this accounted for the difference between the 2 Content-Lengths above.

I replaced each \n with \r\n in the 400 JSON file and imported it back in Postman and ran the request again only to get a 200 which is great but doesn’t explain why lack of \r would cause a 400 Bad Request.

The request is MTOM SOAP Example MTOM SOAP Request for the CheckInAAF Operation · GitHub

I presume the request wasn’t “interpreted” into the correct format because of a lack of \r

1 Like

@tafadzwagonera, on checking your sample payload and your query. Basically \n, \r is used to denote a new line, and it depends on the interpreter how it interprets. The reason you got the error 400(Bad request) depends on how your target service is configured. I just found one query on stackoverflow which contains useful information regarding these new line characters.

Hope this helps.

1 Like

@pranavdavar I’ve just read the linked SO answer. There are all sorts of useful explanations there. This has been helpful.

This is an old message, and I don’t see any other postings about this specific error.
Is it that the issue has been fixed and that Postman user can specify a CR or CR LF ?
Or systems that weren’t flexible enough to handle the differences (due to OS?) are now obsolete?

Is it that the issue has been fixed and that Postman user can specify a CR or CR LF?

Yes and yes.

Or systems that weren’t flexible enough to handle the differences (due to OS?)…

I can’t say for sure but I’d bet that’s very likely.

The context around the problem was that I was programmatically marshalling a SOAP request in a POSIX environment for a third party web service probably running in a Win environment.

How are you able to specify a CR or CR LF in the postman body ? Hopefully, it is something simple as configuration/setting or adding a /r etc ?

Hopefully, it is something simple as configuration/setting or adding a /r etc ?

I don’t know if there’s a configuration setting for line breaks i.e. CR and CRLF in Postman. I couldn’t find it at the time. The process is simple enough. I’d export a collection as json. Open the collection in a text editor like Sublime then modify line breaks (i.e. /r/n into /r), save and import back into Postman.

I understand. Thank you for responding.

1 Like