重定向使用Post方法从code后面的另一页 [英] Redirect to another page using Post method from Code behind
本文介绍了重定向使用Post方法从code后面的另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想实现一个付款service.I将创造背后code一些值,然后通过使用POST方法我有权发布此值,以支付网关和用户必须重定向到该页面。
监守我要创造一些价值观念和保存的一些事情在code后面的分贝我不能使用表单操作。
我怎么能实现呢?
如果我可以发布数据到另外一个页面上我的应用程序,并可以programmically提交该网页时,可能帮助我。
感谢
解决方案
字符串的URL =第三方网址;StringBuilder的POSTDATA =新的StringBuilder();postData.Append(FIRST_NAME =+ HttpUtility.UrlEn code(txtFirstName.Text)+&安培;);
postData.Append(姓氏=+ HttpUtility.UrlEn code(txtLastName.Text));// ETC对所有表单元素//现在发送数据。
StreamWriter的作家=无效;HttpWebRequest的要求=(HttpWebRequest的)WebRequest.Create(URL);
request.Method =POST;
request.ContentType =应用/的X WWW的形式urlen codeD;
request.ContentLength = postData.ToString()长度。
尝试
{
作家=新的StreamWriter(request.GetRequestStream());
writer.Write(postData.ToString());
}
最后
{
如果(作家!= NULL)
writer.Close();
}的Response.Redirect(新页);
在这个海报看一看
I want to implement a Payment service.I will create some values in code behind and then by using post method I have to post this values to Payment gateway and user must redirect to that page.
I can't Use form action becuase I have to create some values and save some thing in db in code behind.
how can I implement this? If I can post data to another page on my app and can submit that page programmically it maybe help me.
Thanks
解决方案
string url = "3rd Party Url";
StringBuilder postData = new StringBuilder();
postData.Append("first_name=" + HttpUtility.UrlEncode(txtFirstName.Text) + "&");
postData.Append("last_name=" + HttpUtility.UrlEncode(txtLastName.Text));
//ETC for all Form Elements
// Now to Send Data.
StreamWriter writer = null;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.ToString().Length;
try
{
writer = new StreamWriter(request.GetRequestStream());
writer.Write(postData.ToString());
}
finally
{
if (writer != null)
writer.Close();
}
Response.Redirect("NewPage");
Have a look at this Poster
这篇关于重定向使用Post方法从code后面的另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文