我想从控制器重定向另一个域服务器。
此外,我必须得到服务器的回复。
如何在ASP.NET MVC中实现这一点?
我们尚未实施“模型”部分。我找到了一个Web表单的解决方案。
答案 0 :(得分:0)
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();
}