
Editorial illustration.
Originally published 16 June 2023; rewritten and reviewed on 15 October 2026.
I ran into this exact problem the first time I integrated a Malaysian payment gateway into an ASP.NET application. The checkout flow needed to validate the customer’s cart on our server, generate a transaction reference and HMAC signature, and then hand the customer over to the gateway’s hosted checkout page using HTTP POST.
My first instinct was to reach for HttpClient.PostAsync in the code-behind. It sent the payload, the gateway responded with 200 OK, and I got a string full of HTML back in C#. Meanwhile, the customer’s browser was still sitting motionless on our checkout page.
That is the moment you realise why “sending a POST request” and “redirecting the user with POST” are two completely different operations.
Three different operations people mix up
When you work with payment gateways like iPay88, eGHL, or older FPX redirect flows, it helps to separate the three actors clearly:
- Server-to-server HTTP client (
HttpClient): Your ASP.NET server talks directly to the gateway’s API. The customer’s browser is not involved at all, so cookies, FPX bank selection screens, and 3D Secure prompts never reach the user. - HTTP redirect (
Response.Redirect): Your server returns a302 Foundor303 See Otherstatus code with aLocationheader. Browsers follow those redirects with aGETrequest, which drops any POST body you wanted to send. (Even307 Temporary Redirectonly preserves the original request’s POST body—it does not let your server inject newly computed fields like a signature.) - Browser-submitted HTML form: Your server renders an HTML
<form method="post">containing the signed fields and instructs the browser to submit it to the gateway URL.
When a gateway’s integration spec says “redirect the customer to our checkout URL via POST”, they almost always mean the third option.
Rendering a controlled POST form from ASP.NET
After you create the pending order in your database and compute the gateway signature on the server, return a lightweight transition page (or render the form in your MVC view / WebForms response) that posts directly to the gateway:
var gatewayUrl = _config["Payments:GatewayCheckoutUrl"]; // from appsettings.json, never user input
var orderRef = HtmlEncoder.Default.Encode(order.ReferenceNo);
var amount = HtmlEncoder.Default.Encode(order.Amount.ToString("0.00"));
var signature = HtmlEncoder.Default.Encode(ComputeHmacSha256(order));
And the HTML rendered to the browser looks like this:
<form id="gateway-handoff" method="post" action="https://payments.example.com/checkout">
<input type="hidden" name="orderReference" value="@orderRef" />
<input type="hidden" name="amount" value="@amount" />
<input type="hidden" name="signature" value="@signature" />
<noscript>
<p>JavaScript is disabled. Click below to continue to the payment page.</p>
</noscript>
<button type="submit">Continue to payment</button>
</form>
Keep a visible submit button even if you trigger document.getElementById('gateway-handoff').submit() from an external script. On slow mobile connections or strict corporate browsers, auto-submit scripts occasionally stall or get blocked by Content Security Policy (CSP) rules if you used an inline onload attribute. Using an external script file loaded with a nonce or hash avoids loosening your script-src policy.
Do not trust the form fields or the destination
Because the <form> lives in the customer’s browser, every hidden <input> is trivial to inspect and edit in DevTools before submission. That is why every serious gateway requires a cryptographic signature (usually HMAC-SHA256 or SHA512) calculated with your merchant secret key on the server.
Two rules I always enforce on the handoff page:
- Pull the
actionURL from server configuration, never from a query string or posted form field. Accepting an arbitrary destination turns your checkout page into an open form-post proxy. - HTML-encode every dynamic value (
HtmlEncoder.Default.Encodein ASP.NET Core,HttpUtility.HtmlAttributeEncodein older WebForms). A customer name or remark containing"will break out of thevalue="..."attribute and corrupt the payload.
Verify the payment separately from the browser return
Getting the customer to the gateway is only half the flow. In Malaysia especially, plenty of users complete an FPX transfer on their banking app and close the browser tab before the gateway redirects them back to your ReturnUrl.
Never mark an order as paid solely because the browser landed on /payment/success. Always treat the browser return as a UI hint (“We are checking your payment”) and rely on the gateway’s server-to-server callback (IPN/webhook) or a direct status query API—verifying the signature and amount (RM value and currency) against your database record before fulfilling the order.
Once you name which machine is speaking to which—server to server, server to browser, or browser to gateway—this whole class of redirect bugs disappears.