HttpWebRequest.GetResponse从支付网关返回html标签

时间:2018-01-17 21:04:22

标签: c# asp.net httpwebrequest httpwebresponse

我正在尝试通过此链接(https://docs.payfort.com/docs/merchant-page-two/build/index.html)在我的asp.net网站中集成支付网关。

以下是我的示例代码:

protected void btnPay_Click(object sender, EventArgs e)
{
    ASCIIEncoding encoding = new ASCIIEncoding();
    string data = string.Format("service_command={0}&access_code={1}&merchant_identifier={2}&merchant_reference={3}&language={4}&signature={5}&token_name={6}&expiry_date={7}&card_number={8}&card_security_code={9}&card_holder_name={10}&remember_me={11}&return_url={12}",
        "TOKENIZATION", "zx0IPmPy5jp1vAz", "CycHZxVj", "XYZ9239-yu898","en", "d7c185c475ac0e3", "Op9Vmp", "1705", "4005550000000001","123", "John Smith","NO", "http://localhost:1093/Default.aspx");
    byte[] bytes = encoding.GetBytes(data);

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create("https://sbcheckout.payfort.com/FortAPI/paymentPage");
    httpRequest.Method = "POST";
    httpRequest.ContentType = "application/x-www-form-urlencoded";
    httpRequest.ContentLength = bytes.Length;
    using (Stream stream = httpRequest.GetRequestStream())
    {
        stream.Write(bytes, 0, bytes.Length);
        stream.Close();
    }
    StreamReader rdr = new StreamReader(httpRequest.GetResponse().GetResponseStream());
    string result = rdr.ReadToEnd();
    rdr.Close();
    httpRequest.GetResponse().Close();
}

enter image description here

现在我不明白的是,我得到的回复是我的页面的相同HTML,其中包含form标签的action属性中的所有参数,我不知道这是什么以及我要做什么它。任何人都可以帮我这个。 我附上了我得到的回复,请同时查看

谢谢

click on the link to view response

1 个答案:

答案 0 :(得分:1)

文档说明:

  

请记住 - 商家应该开发一个不发送数据的表单   到他的网站,但直接将表格提交给PayFort。

你正在做他们要求你做的事情。

我不认为这是用作API。您的表单应该直接将信息提交给他们的系统。然后,他们将使用return_url参数显示工作流程中的下一页。该URL将包含结果的详细信息。

您可以随时与他们联系,并要求提供备用,后端友好的集成。