如何使用 post 方法重定向到 mvc 中的另一台服务器?
How to redirect to another server in mvc using post method?
我想从控制器重定向到另一个域服务器。
我还必须从服务器获得响应。
如何在 ASP.NET MVC 中实现这一点?
我们还没有实现模型部分。我找到了 Web 表单的解决方案。
You can use the HttpWebRequest class to make the post to the other server and then redirect as normal
//code would be something like this
var httpRequest = (HttpWebRequest)WebRequest.Create("http:your url");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
string data = "key=value&key2=value2";
byte[] dataArray = Encoding.UTF8.GetBytes(data);
httpRequest.ContentLength = dataArray.Length;
//actual code to call another server
using(Stream requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(dataArray, 0, dataArray.Length);
var webResponse = (HttpWebResponse)httpRequest.GetResponse();
}
我想从控制器重定向到另一个域服务器。
我还必须从服务器获得响应。
如何在 ASP.NET MVC 中实现这一点?
我们还没有实现模型部分。我找到了 Web 表单的解决方案。
You can use the HttpWebRequest class to make the post to the other server and then redirect as normal
//code would be something like this
var httpRequest = (HttpWebRequest)WebRequest.Create("http:your url");
httpRequest.Method = "POST";
httpRequest.ContentType = "application/x-www-form-urlencoded";
string data = "key=value&key2=value2";
byte[] dataArray = Encoding.UTF8.GetBytes(data);
httpRequest.ContentLength = dataArray.Length;
//actual code to call another server
using(Stream requestStream = httpRequest.GetRequestStream())
{
requestStream.Write(dataArray, 0, dataArray.Length);
var webResponse = (HttpWebResponse)httpRequest.GetResponse();
}