C# 使用HttpWebRequest c在发布数据后重定向到Url#
我正在整合现金支付网关 我需要使用Post方法发布一些数据。然后我想重定向到支付网关网站 到目前为止,我已经做到了C# 使用HttpWebRequest c在发布数据后重定向到Url#,c#,asp.net,asp.net-mvc,payment-gateway,C#,Asp.net,Asp.net Mvc,Payment Gateway,我正在整合现金支付网关 我需要使用Post方法发布一些数据。然后我想重定向到支付网关网站 到目前为止,我已经做到了 [HttpPost] public ActionResult Index(string getAmount) { // some more process var getResponce = ExecutePost(getTokenCode); } private string ExecutePost(string tokenCode) {
[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页面字符串。但我想在支付网关网站上重定向 您可以使用
返回重定向(“URl”)
若要重定向到其他url,请找人帮助我。有什么帮助吗?它向您展示了如何使用该函数从MVC控制器重定向到外部url。@JasonEvans:但它不会使POST重定向。@micheal berezin:但它不会使POST重定向。