【发布时间】:2014-02-20 14:14:43
【问题描述】:
我们需要从外部表单中获取 post 参数。示例:
第一次申请 - 表格
<form method="post">
<input type="text" name="privet" value="TestValue" />
<input type="submit" value="submit" />
</form>
第一个应用程序 - 控制器
[HttpPost]
public ActionResult Test(string privet)
{
return Content("Answer: " + privet);
}
第二个应用程序(外部)——控制器
WebRequest _wr = WebRequest.Create("http://SomeExternalDomain/Home/Test");
_wr.Method = "POST";
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes("privet=SomeValue");
_wr.ContentType = "application/x-www-form-urlencoded";
_wr.ContentLength = byteArray.Length;
using (Stream dataStream = _wr.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
using (HttpWebResponse _response = (HttpWebResponse)_wr.GetResponse())
{
using (Stream _dataStream = _response.GetResponseStream())
{
using (StreamReader _reader = new StreamReader(_dataStream))
{
return _reader.ReadToEnd();
}
}
}
如果我们在单个应用程序中发送 Post,则 post 数据被接受,但来自外部应用程序的 post 数据被丢弃。 (而不是 POST,方法是 GET 没有数据)。
在这两种情况下,在 IIS 日志中注册的 POST 请求。
2014-02-20 13:59:45 ::1 POST /Home/Test ...
2014-02-20 14:12:41 192.168.15.18 POST /Home/Test ...
哪些地方可以限制外部发帖请求?谢谢!
【问题讨论】:
标签: asp.net asp.net-mvc asp.net-mvc-4 iis