[英]Post from controller action to third party website
I have an MVC page with a form which when submitted posts firstly to my controller and handled by my controller action. 我有一个带有窗体的MVC页面,该窗体首先提交到我的控制器并由我的控制器动作处理。 At the controller action I manipulate the posted data and then need to re-POST that data to a third party webpage.
在控制器操作中,我操纵发布的数据,然后需要将该数据重新发布到第三方网页。
How do I redirect and re-POST form values to a third party web page from within an MVC post action? 如何在MVC发布操作中将表单值重定向并重新发布到第三方网页?
Update 更新
This is possible in .Net MVC and WebForms. 在.Net MVC和WebForms中,这是可能的。 See solution below.
请参阅下面的解决方案。
You need to handle the [Post] Action by: 您需要通过以下方式处理[发布]操作:
You must use the 307 Temporary Redirect status response code as it maintains the POST method of the request. 您必须使用307临时重定向状态响应代码,因为它维护了请求的POST方法。 If you use the 302 status response, the browser will convert the request into a GET request and drop the form values that were originally posted.
如果使用302状态响应,浏览器会将请求转换为GET请求,并删除最初发布的表单值。
How does it work? 它是如何工作的?
This works by having your server communicate back to the browser that the location of the page has changed. 这可以通过使服务器与浏览器通信来通知页面位置已更改,从而起作用。 The Browser then rePOST's the form data to the new page location.
然后,浏览器将表单数据重新发布到新页面位置。
Example of usage below: 以下用法示例:
[HttpPost]
public ActionResult Test()
{
var amount = Request["amount"];
string url = "/Home/Test2";
HttpContext.Response.AddHeader("Location", url);
return new HttpStatusCodeResult(307);
}
public ActionResult Test2()
{
var x = Request["amount"];
Response.Write("Stuff 123...." + x);
return View();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.