简体   繁体   English

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

[英]Redirect to Url after Post data using HttpWebRequest c#

I'm integrating CashU Payment gateway. 我正在集成CashU Payment网关。

I need to Post some data using POST method. 我需要使用POST方法发布一些数据。 then I want to redirect to payment gateway site. 那么我想重定向到支付网关站点。

I have done so far 到目前为止我已经做过

 [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;

        }

My ExecutePost method is returing a Html page string in string formate. 我的ExecutePost方法正在重整字符串形式的HTML页面字符串。 But I want to redirect on payment gateway site. 但是我想在支付网关站点上重定向。

you can use 您可以使用

return Redirect("URl"); 返回Redirect(“ URl”);

to redirect to a different url 重定向到其他网址

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM