Asp.net IIS 7上的外部POST请求
我们需要从外部表单获取post参数。例如: 第一次申请-表格Asp.net IIS 7上的外部POST请求,asp.net,asp.net-mvc,asp.net-mvc-4,iis,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Iis,我们需要从外部表单获取post参数。例如: 第一次申请-表格 <form method="post"> <input type="text" name="privet" value="TestValue" /> <input type="submit" value="submit" /> </form> 第二个应用程序(外部)--控制器 [HttpPost] public ActionResult Test(string priv
<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将被丢弃。(方法上的GET withoud data代替POST)
在这两种情况下,都会在IIS日志上注册POST请求
2014-02-20 13:59:45::一个POST/Home/Test…
2014-02-20 14:12:41 192.168.15.18发布/主页/测试…
哪里可以限制外部post请求?谢谢 您的代码看起来不错。可以简化为:
using (var client = new WebClient())
{
var values = new NameValueCollection
{
{ "privet", "SomeValue" },
};
byte[] result = client.UploadValues("http://SomeExternalDomain/Home/Test", values);
return Encoding.UTF8.GetString(result);
}
但我想这并不能解决问题。您似乎提到了GET请求。可能您的外部应用程序是一个web应用程序,您在发出POST请求后正在重定向客户端浏览器