Adding requests data to headers

IĀ“m trying to add the requests data to the headers. besides some other variables which work propper, trying to add the requests data results in a ā€œCould not get any responseā€ error.

HereĀ“s what I do:

Pre-request Script:

var body = request.data;
if(_.isEmpty(body)) body = ā€œā€;
postman.setEnvironmentVariable(ā€˜mybodyā€™, body);

Headers:

X-Body {{mybody}}

Can one explain why the error occures? IĀ“ll do the same with some other variables without any problems. adding the one for request data leads to the error.

It is highly unusual to send a ā€œbodyā€ using a header.

While there is not limitation when it comes to the HTTP protocol, the server may reject your value because it is too long.
Have you tried with a shorter value?

Thanks for the reply!

I agree that this is unusual, and itĀ“s for debugging only. I used it already successfull, but only with empty strings (""), which worked well for me.

Lately die postman console gave me the hint (View -> Show Postman Console) that there are unprocessable characters in my provided body (it was a short json). Without linebreaks and tabs I could send the data in the header.

But as you already mentioned, this was not for production rather than for debugging and lately it solved my problem.

Thanks for the help anyways!