madskristensen / RestClientVS

Other
66 stars 14 forks source link

Newlines in application/x-www-form-urlencoded body should not be sent in request #31

Closed Halofreak1990 closed 2 years ago

Halofreak1990 commented 2 years ago

When building a request body with ContentType application/x-www-form-urlencoded, I usually place each parameter on a new line for readability, like so: param1=value1 &param2=value2 &param3=value3 ...

This works just fine in RESTClient for VSCode, but here, it sends the newlines as part of the parameter values, leading to 400 (Bad Request) errors when POST-ing to the server, as it does not expect newlines.

matt3274 commented 2 years ago

This is an issue for me as well.

This works:

POST https://myserver/mypath/myoperation HTTP/1.1
content-type: application/x-www-form-urlencoded

f=json&inputLocations=123,45;123,46

But this doesn't:

POST https://myserver/mypath/myoperation HTTP/1.1
content-type: application/x-www-form-urlencoded

f=json
&inputLocations=123,45;123,46
matt3274 commented 2 years ago

FYI, I found that changing DocumentParser.cs, line 263 from: currentRequest.Body += prevEmptyLine + item.Text; to: currentRequest.Body += prevEmptyLine + item.TextExcludingLineBreaks;

fixes the problem for me.