【发布时间】:2015-05-29 08:25:17
【问题描述】:
我想从控制器重定向到另一个域服务器。
我还必须得到服务器的响应。
如何在 ASP.NET MVC 中实现这一点?
我们尚未实现模型部分。我找到了 Web 表单的解决方案。
【问题讨论】:
-
你不能用 C# 代码做一个
HttpClientPOST 并得到响应吗?
标签: javascript c# jquery asp.net-mvc asp.net-ajax
我想从控制器重定向到另一个域服务器。
我还必须得到服务器的响应。
如何在 ASP.NET MVC 中实现这一点?
我们尚未实现模型部分。我找到了 Web 表单的解决方案。
【问题讨论】:
HttpClient POST 并得到响应吗?
标签: javascript c# jquery asp.net-mvc asp.net-ajax
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();
}
【讨论】: