Skip to content

How to pass GET parameters of gateway endpoint to POST backend method as body application/x-www-form-urlencoded? #1946

Answered by garybond
ernoli asked this question in Q&A
Discussion options

You must be logged in to vote

I've had to do the same thing recently to take a GET request with parameters and assemble some json to be POSTed to the back-end service,
I ended up using the DelegatingHandler.

This should get you off in the right direction...

public class ConvertGetToPostHandler : DelegatingHandler
{
    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        //do stuff to get/validate your querystring parameters, e.g.
        var yourFormData = request.RequestUri.Query.TrimStart('?');

        request.Content = new StringContent(yourFormData, Encoding.UTF8, "application/x-www-form-urlencoded");
        request.Method =

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@raman-m
Comment options

Answer selected by raman-m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Configuration Ocelot feature: Configuration Delegating Handlers Ocelot feature: Delegating Handlers Routing Ocelot feature: Routing
3 participants
Converted from issue

This discussion was converted from issue #947 on January 27, 2024 12:59.