【发布时间】:2011-01-07 19:21:10
【问题描述】:
我有一个收集数据并将“POST”发送到另一个站点的页面。我可以将他的站点 url 放在表单标签的操作中,但我想在切换站点之前将信息记录在我的数据库中。到目前为止,在 ActionResult 中我有:
[HttpPost]
public ActionResult MyPage(MyPageModel model)
{
if (ModelState.IsValid)
{
StoreDate(model.fld1, model.fld2)
var encoding = new ASCIIEncoding();
var postData = "";
foreach (String postKey in Request.Form)
{
var postValue = Encode(Request.Form[postKey]);
postData += string.Format("&{0}={1}", postKey, postValue);
}
var data = encoding.GetBytes(postData);
// Prepare web request...
var myRequest = (HttpWebRequest)WebRequest.Create("https://www.site2.com");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
// Send the data.
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Flush();
newStream.Close();
有谁知道如何完成此操作并使用适当的“返回”变量将此数据发布到其他站点。
我已根据以下回复编辑了 sn-p。
【问题讨论】:
标签: c# asp.net-mvc-2 post redirect