1

In C# code I need to post form to other website for payment gateway, I can do it by adding some html tags to my webform and submitpage on body load. I I wants to do it in more proper way using HttpClient. but when i post my http call to client url with my data values. my page dont redirect me to payment website.is there any that my code work in same way like when i post my form manualy. Here is code snippet for form submisttion manualy:(its working)

<form action="https://somewebsite.com/someurl" method="POST" target="_blank"> <input name="token" value="MyTokenParameter" hidden = "true"/> 
<input name="postBackURL" value="http://mywebsite.com/status.aspx" hidden = "true"/> 
<input value="confirm" type = "submit" name= "pay"/> 
</form>

Here is my C# code to submit the same data with httpclient:(its not redirecting user to payment website)

private async Task ProcessAsyncRequest()
{
    using (var client = new HttpClient())
    {
        var values = new List<KeyValuePair<string, string>>();
        values.Add(new KeyValuePair<string, string>("token", "MyTokenParameter"));
        values.Add(new KeyValuePair<string, string>("postBackURL","http://mywebsite.com/status.aspx"));
        var content = new FormUrlEncodedContent(values);
        var response = await client.PostAsync("https://somewebsite.com/someurl",content);
        var responseString = await response.Content.ReadAsStringAsync();
        Response.Write(responseString);
    }
}

is it possible with httpclient to let user move to client site in response?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
M Imran
  • 109
  • 7
  • 1
    i think payment gateway has api and you are supposed to send data to them by using api they recommend. – Bhuban Shrestha Aug 24 '17 at 04:45
  • yes they provide me api, after submitting data to that api i get token which i need to post again with another postback url – M Imran Aug 24 '17 at 04:57

0 Answers0