AnWeber/vscode-httpyac

Incorrect POST requests using application/x-www-form-urlencoded in case XML contains '+' symbol

dreik opened this issue · 1 comments

I'm trying to send request like this

POST /MyApi.asmx/request HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic {{basicuser}}{{basicpassword}}

xmlRequest=<Request>
    <User>some.user+xml@some.domain</User>
    <Password>randompassword</Password>
    <RequestMethod>GetAvailability</RequestMethod>
    <SearchParameters>
        <Product>1</Product>
        <ShopId>1</ShopId>
        <Currency>USD</Currency>
    </SearchParameters>
</Request>

I'm getting following as the actual request logged in my db:

<Request>
    <User>some.user xml@some.domain</User>
    <Password>randompassword</Password>
    <RequestMethod>GetAvailability</RequestMethod>
    <SearchParameters>
        <Product>1</Product>
        <ShopId>1</ShopId>
        <Currency>USD</Currency>
    </SearchParameters>
</Request>

Storing User and Password as variables also doesn't work:

  • in case of .env file variable it breaks even mouseover: instead of {{Password}} value it's showing {{User}} value when you do mouseover on {{Password}}
  • in case of local variable it shows nothing on mouseover (additionally tested, and it very looks like that mouseover works in very strange way when you have a mixture of .env file variables and @local variables within same request)

Just to confirm - I've tested same requests in postman, and it works properly, so the issue isn't on the backend side (i.e parsing reqs or storing in sql)

Anyway, your solution is really great and very helpful! Thank you so much !

@dreik for application/x-www-form-urlencoded POST request the body needs to be Percent-Encoded (see MDN). I use encodeUrl package but + signs will not get encoded. You need to do it yourself (see AnWeber/httpyac#677)

POST /MyApi.asmx/request HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Authorization: Basic {{basicuser}}{{basicpassword}}

xmlRequest=<Request>
    <User>some.user%2Bxml@some.domain</User>
    <Password>randompassword</Password>
    <RequestMethod>GetAvailability</RequestMethod>
    <SearchParameters>
        <Product>1</Product>
        <ShopId>1</ShopId>
        <Currency>USD</Currency>
    </SearchParameters>
</Request>