Home > front end >  Blazor Navigate to other page with post request
Blazor Navigate to other page with post request

Time:10-17

In my Hosted Blazor web assembly application, we would like to implement a third party payment gateway by redirecting to the third party website. In order to access the third party page, we need to redirect to the third party page and supply all the required parameter using POST/GET method.

We tried with

NavigationManager.NavigateTo("https://sandbox.merchant.razer.com/RMS/pay/MerchantID/?"
  "Param1=data"
  "&param2=data"
  "&..."
  "&returnurl=data"
  "&cancelurl=data"
")

and it work perfectly.

But we believe we should implement a POST method instead of the GET method when redirecting to the payment page.

I try in a postman and resend the param using the post method with param in form-data content, and it return the Html content perfectly as expected.

Is there any way we can do this in blazor?

I used to do the same in php, but I am not sure about this in Blazor.

If possible, we would like the user to not be able to see all the parameter that we send because there might be some sensitive information.

CodePudding user response:

I have a blazor payment project with POST method required. Instead of NavigateTo the payment gateway, I redirect to own PaymentRequest.cshtml in the project with following content

<form id="form1" method="post" name="ePayment" action="@Model.PaymentEndPoint">
    @foreach (var item in Model.PaymentRequest.ToDictionary())
    {
        <input type="hidden" name="@item.Key" value="@item.Value" />
    }
</form>

<script>
    window.onload = function(){
    document.forms[0].submit();
    };
</script>

You may modify the content with your own key value pair. Once the page loaded, it will POST to the Payment Gateway

  • Related