curl -vvv -X POST "http://localhost:4000/set?somekey=spaced value"
Running this command, we have:
POST /set?key=k ey HTTP/1.1 Host: localhost:4000 User-Agent: curl/7.61.0 Accept: /
< HTTP/1.1 400 Bad Request
In this example, curl doesn't encode URL data automatically and we have the following error on server log:
INFO:tornado.general:Malformed HTTP message from ::1: Malformed HTTP request line
To send this as valid requests, as expected from the begining, it should be send with two main changes:
- Split the querystring part and move to option --data-urlencode. Using this option, curl automatically consider this request as POST;
- Add -G option to send all --data-urlencode value on querystring, as GET. It can still be combined with -XPOST option to send as POST.
The final command is:
curl -vvv -G -X POST "http://localhost:4000/set" --data-urlencode "somekey=spaced value"
Running this, we have the encoded data being sent on the query string part:
POST /set?key=k%20%20y HTTP/1.1 Host: localhost:4000 User-Agent: curl/7.61.0 Accept: /
< HTTP/1.1 201 Created
On server LOG, now, we receive:
INFO:tornado.access:201 POST /set?key=k%20%20y (::1) 0.91ms
The reference where I found this helpful info, was the following link: https://www.systutorials.com/241492/how-to-encode-spaces-in-curl-get-request-url-on-linux/