如何从HttpResponseMessage获取参数

时间:2016-09-27 10:27:58

标签: asp.net asp.net-mvc asp.net-mvc-4 razor asp.net-web-api

我在支付网关URL上发布了4个参数,在响应服务器中发送回名为auth_token&的参数。一项PostBackUrl。

我不认为如何从ASP.NET MVC中的respose获取这些参数(auth_token& postBackURL)????

以下是我的代码。

        var client = new HttpClient();
        var values = new List<KeyValuePair<string, string>>();
        values.Add(new KeyValuePair<string, string>("storeId", "1234"));
        values.Add(new KeyValuePair<string, string>("amount", "1000"));
        values.Add(new KeyValuePair<string, string>("postBackURL","http://www.smmotors.org"));
        values.Add(new KeyValuePair<string, string>("orderRefNum", "1101"));

        var content = new FormUrlEncodedContent(values);

        HttpResponseMessage response =   client.PostAsync("https://easypaystg.easypaisa.com.pk/easypay/Index.jsf", content).Result;

以下是插件集成文档。

商家需要在以下网址上将以下参数POST到Easypay:

沙箱环境: https://easypaystg.easypaisa.com.pk/easypay/Index.jsf

金额 storeId postBackURL orderRefNum

成功重定向后,客户将登陆Easypay Checkout屏幕,其中有关于交易信息的表格。

  1. 在完成步骤1中的表单后,客户将按下Proceed Button并在第一步中使用postbackURL变量中给出的相同URL返回商家网站。这将是商家网站上的确认屏幕,用于在Easypay和商家网站之间进行握手。 Easypay将名为auth_token的参数发送回postbackURL,后者作为GET参数发送。现在,商家需要将以下两个参数重新发回以下网址:
  2. 沙箱环境: https://easypaystg.easypaisa.com.pk/easypay/Confirm.jsf

    auth_token postBackURL

    在此重定向之后,Easypay验证商家发送的auth_token与上一步中的auth_token,并且在成功验证后,它将使客户登陆成功的结账屏幕,将两个变量发送回第二个postBackURL:

    状态 desc orderRefNumber

1 个答案:

答案 0 :(得分:0)

您可以像这样使用获取响应键

  public ActionResult AdvPaymentResponse()
    {
        List<PaypalAddDataValueModel> keyvalueList = new List<PaypalAddDataValueModel>();
        var postdata = System.Web.HttpContext.Current.Request.Form;
        foreach (var item in postdata)
        {
            PaypalAddDataValueModel datavalue = new PaypalAddDataValueModel();
            datavalue.Key = item.ToString();
            datavalue.Value = System.Web.HttpContext.Current.Request.Form[item.ToString()];
            keyvalueList.Add(datavalue);
            // var data = System.Web.HttpContext.Current.Request.Form[item.ToString()];
        }
        AdvPaypalResponse obj = new AdvPaypalResponse();
        obj.AVSZIP = keyvalueList[0].Value;
        obj.BILLTOEMAIL = keyvalueList[1].Value;
        obj.TYPE = keyvalueList[2].Value;
        obj.ZIPTOSHIP = keyvalueList[3].Value;
        obj.BILLTOLASTNAME = keyvalueList[4].Value;
        obj.BILLTONAME = keyvalueList[5].Value;

    }