1

我面临的问题是,payfort API 应该返回一些 json。但相反,我得到了一些包含一些隐藏字段的 html。我看里面没有写错误。

这是我的代码

string access_code = string.Empty,
            amount = string.Empty,
            currency = string.Empty,
            customer_email = string.Empty,
            merchant_reference = string.Empty,
            order_description = string.Empty,
            language = string.Empty,
            merchant_identifier = string.Empty,
            signature = string.Empty,
            command = string.Empty;

        access_code = "X78979879h8h8h8";
        amount = "1000";
        command = "AUTHORIZATION";
        currency = "AED";
        customer_email = "zetawars@hotmail.com";
        language = "en";
        merchant_identifier = "RaskdQuCc";
        merchant_reference = "ASASASASASADSS";
        order_description = "Some order details";
        signature = "";

        string signature_string = "PASSaccess_code="+access_code+"amount="+amount+"command="+command+"currency="+currency+"customer_email"+customer_email+"language"+language+"merchant_identifier"+merchant_identifier+"merchant_reference"+merchant_reference+"order_description"+order_description+"PASS";

        signature = getHashSha256(signature_string);
        string url = "https://sbcheckout.payfort.com/FortAPI/paymentPage";
        string param = "access_code" + access_code + "&amount=" + amount + "&currency=" + currency + 
            "&customer_email=" + customer_email + "&merchant_reference=" + merchant_reference + 
            "&order_description=" + order_description + "&language=" + language + "merchant_identifier=" 
            + merchant_identifier + "&signature=" + signature + "&command=" + command;


        using (WebClient wc = new WebClient())
        {
            wc.Headers[HttpRequestHeader.ContentType] = "application/json";
            //wc.Headers.Add("Content-Type", "application/json");
            string HtmlResult = wc.UploadString(url, param);
        }
4

2 回答 2

2

尝试为下面的标题添加值

wc.Headers[HttpRequestHeader.Authorization]
wc.Headers[HttpRequestHeader.TenantId]
wc.Headers[HttpRequestHeader.Client-Type]
wc.Headers[HttpRequestHeader.Protocol]

为我工作!

于 2016-08-30T11:27:03.880 回答
0

首先对响应进行编码

string responseString = Encoding.UTF8.GetString(response);

使用 HtmlDocument (HtmlAgilityPack)

var html = new HtmlDocument();
var tokenValue = "";
html.LoadHtml(responseString);

将其加载到 html 后,您可以查询字段和值。

var tokenFormIdElement = 
          html.DocumentNode.SelectSingleNode("//input[@name='token']");
tokenValue = tokenFormIdElement.GetAttributeValue("value", "");
于 2017-12-11T09:03:30.990 回答