0

Ques : I want Post Or Execute on my page and Get Response on my same page which page i had posted without redirecting or going on another page.

I had created a dynamic web form.

<form id="PostForm" name="PostForm" action="https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm" method="POST">
    <input type="hidden" name="merchant_code" value="XYZ">
    <input type="hidden" name="encdata" value="+yw5GSwy5ns7XP0/XYZ/6YEkdfjs fjvnsdr+cecGpm0kwhgopO3Jc9RHTld+sj7h6EKm5tcFGN8/oc5yG9E2JfXeboxlkw31bkrD4fXFr0=">
</form>

i like to post Request and get response this piece of HTML Code using C# without redirecting on Another Page.

I was try to use this below mentioned code but its not working values for Query string.

public bool SendSMS(string mobileNo, string message)
    {
        try
        {

            string strUrl =  "https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm.......... SO On...";
            WebRequest request = HttpWebRequest.Create(strUrl);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream s = response.GetResponseStream();
            StreamReader readStream = new StreamReader(s);
            string dataString = readStream.ReadToEnd();
            response.Close();
            s.Close();
            readStream.Close();

            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }

They have require Values in only Form as above mentioned with Post Method Please suggest ASAP.

  • so you need to remove this? `action="https://merchant.PaymentGateway.com/thirdparties/doubleverification.htm"` – Anonymous Duck Jul 13 '16 at 05:37
  • I need to perform post on this sample URL, and main problem is that it accept only POST Method, Query string URL Does not acceptable. If I try with Query string through URL then show me error. But i am not able to get how and where i have to remove URL and why pls elaborate. – Gautam Kumar Sahu Jul 13 '16 at 06:02
  • WebRequest can send as POST; https://msdn.microsoft.com/en-us/library/system.net.webrequest.method(v=vs.110).aspx – Allan S. Hansen Jul 13 '16 at 06:06
  • But it Simply request a URL, and i am looking for Send / POST a whole form as Above. `WebRequest.Create("http://www.contoso.com"); ` – Gautam Kumar Sahu Jul 13 '16 at 06:15
  • WebRequest does not simply request an url. It can submit form/POST. When doing webforms it is much easier to just post back to your server, then do a webrequest form submit from your server to the payment gateway and then return that result / redirect based on that. Especially also to keep stuff like merchant keys and tokens serverside. – Allan S. Hansen Jul 13 '16 at 06:53

1 Answers1

0

I got Answer for This Query.

  protected void Page_Load(object sender, EventArgs e)
{
    string ForChecksum = string.Format("Sbi_txn_id={2}|arn={0}|amount={1}", "08072016012003001", "1", "1234567890");
    DoubleVerificationCheck(ForChecksum.Trim());
}

public string DoubleVerificationCheck(string data)
{
    NameValueCollection requestNameValue = new NameValueCollection();
    string postData = "encdata=" + data + "|merchant_code=XYZ";
    NameValueCollection nameValue = new NameValueCollection();
    nameValue.Add("merchant_code", "XYZ");
    nameValue.Add("encdata", data);
    string responseMsg = PostRequest("https://merchant.Payemtgateway.com/doubleverification.htm", nameValue);
   return responseMsg;

}

public static string PostRequest(string uri, NameValueCollection pairs)
{
    byte[] response = null;
    using (WebClient client = new WebClient())
    {
        response = client.UploadValues(uri, pairs);
    }
    return System.Text.Encoding.UTF8.GetString(response);
}