Skip to content

Ability to add query parameters using HttpRequest::setParameter when the method is POST #2489

@betsch85

Description

@betsch85

Is your feature request related to a problem? Please describe.
When I needed to add a query parameter to a HttpRequest, I used setParameter("key", "value"), which worked as expected when the method was GET, but when the method is POST and the content type is multipart/form-data, setParameter adds the parameter to the body. I also tried to add the query parameter manually via setPath("/endpoint?key=" + value), and since value has a space in it, I ended up using setPath("/endpoint?key=" + utils::urlEncodeComponent(value) (just like in the HttpRequest implementation) but for some reason that did not work
As I was writing this I found out that setPath() automatically encodes the path (maybe add something like "(see setPathEncode())" to the setPath doc comment) and it worked, but I'd prefer setQueryParameter as you could keep it consistent across requests, independent of the HTTP method

Describe the solution you'd like
I'd like to have either an overload for setParameter to explicitly specify query/body, or a pair of setQueryParameter/setBodyParameter functions where the former always adds to the query and the latter only works when the content type is multipart/form-data or application/x-www-form-urlencoded and will throw otherwise

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions