使用HttpWebRequest c#发布数据后重定向到Url

时间:2015-07-11 18:48:59

标签: c# asp.net asp.net-mvc payment-gateway

我正在整合CashU支付网关。

我需要使用 POST 方法发布一些数据。然后我想重定向到支付网关站点。

到目前为止我已经完成了

 [HttpPost]
public ActionResult Index(string getAmount)
{
// some more process
 var getResponce = ExecutePost(getTokenCode);
}


 private string ExecutePost(string tokenCode)
        {
            var cashuLink = ConfigurationManager.AppSettings["CashULink"].ToString();
            HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(cashuLink);


            var postData = "Transaction_Code="+tokenCode;
            postData += "&test_mode=1";
            var data = Encoding.ASCII.GetBytes(postData);
            webReq.Method = "POST";
            webReq.ContentType = "application/x-www-form-urlencoded";
            webReq.ContentLength = data.Length;
            using (var stream = webReq.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            var response = (HttpWebResponse)webReq.GetResponse();

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

            return responseString;

        }

我的 ExecutePost 方法正在字符串格式化中回滚Html页面字符串。但我想在支付网关站点上重定向。

1 个答案:

答案 0 :(得分:0)

你可以使用

  

返回重定向(“URl”);

重定向到其他网址