user14798284
user14798284

Reputation: 11

How to Post & Get Form Data in Blazor?

Currently I'm working on an integration with payment gateway which is using asp.

Below are the sample given.

Post Form Data

// Post Payment Data
<form method="post" name="ePayment" action="https://testing.com/ePayment.asp">
        <input type="hidden" name="MerchantCode" value="AAA">
        ...
        <input type="submit" value="Proceed with Payment" name="Submit">
</form>

Get Form Data

// Get Payment Response
<%
    MerchantCode = Request.Form("MerchantCode")
    ...
    Status = Request.Form("Status")
%>

IF Status = 1 THEN
    Response.Write "Thank you for payment."
ELSE
    Response.Write "Payment fail."

I have tried the following but the parameters seems not being posted and redirected.

var formContent = new FormUrlEncodedContent(new[]
{
    new KeyValuePair<string, string>("MerchantCode", "AAA")    
});

var myHttpClient = new HttpClient();
var response = await myHttpClient.PostAsync(uri.ToString(), formContent);

May I know what is the best way to get it work in Blazor?

Thanks

Upvotes: 1

Views: 2716

Answers (1)

Daniel S&#225;nchez
Daniel S&#225;nchez

Reputation: 11

Use this code:

    var formContent = new FormUrlEncodedContent(new[]{
        new KeyValuePair<string, string>("username", "myusername"),
        new KeyValuePair<string, string>("password", "myPa$$word")
    });
    var response = await http.PostAsync("security/login", formContent);

works correctly!

Upvotes: 1

Related Questions