sending a POST request with a specific page content, and receiving a Response after

0
0

I have to make calls to mobilPay API (a local payment provider); The instructions looks like: “A page on your website initiates an action on a mobilPay API server by sending a request to the server. This request will always be send using the method POST to one of the payment URL”.

The asp code provided looks like below. How can I emulate that in Wisej? I mean sending a POST request with a specific page content, and receiving a Response after that?

 

try
{
//lots of fields to fill, generating some XML…
System.Collections.Specialized.NameValueCollection coll = new System.Collections.Specialized.NameValueCollection();
coll.Add(“data”, encrypt.EncryptedData);
coll.Add(“env_key”, encrypt.EnvelopeKey);
HttpHelper.RedirectAndPOST(this.Page, urlMobilPay, coll);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
public static class HttpHelper
{
private static String PreparePOSTForm(string url, NameValueCollection data)
{
string formID = “PostForm”;
StringBuilder strForm = new StringBuilder();
strForm.Append(“<form id=\”” + formID + “\” name=\”” + formID + “\” action=\”” + url + “\” method=\”POST\”>”);
foreach (string key in data)
{
strForm.Append(“<input type=\”hidden\” name=\”” + key + “\” value=\”” + data[key] + “\”>”);
}
strForm.Append(“</form>”);
StringBuilder strScript = new StringBuilder();
strScript.Append(“<script language=’javascript’>”);
strScript.Append(“var v” + formID + ” = document.” + formID + “;”);
strScript.Append(“v” + formID + “.submit();”);
strScript.Append(“</script>”);
return strForm.ToString() + strScript.ToString();
}
public static void RedirectAndPOST(Page page, string destinationUrl, NameValueCollection data)
{
string strForm = PreparePOSTForm(destinationUrl, data);
page.Controls.Add(new LiteralControl(strForm));
}
}

  • You must to post comments
Showing 0 results
Your Answer

Please first to submit.