Blazor Navigate to other page with post request
Asked Answered
R

1

3

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.

Retrograde answered 13/10, 2022 at 16:46 Comment(2)
Does this process start with user interaction? Like they are clicking a payment button?Heaviness
@MisterMagoo Yes, there is a button and it is bind to Submit(). While this redirect code is in the Submit() method itselfRetrograde
S
2

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

Selfrespect answered 15/10, 2022 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.