[英]ASP.NET MVC-2 How can you recieve a POST from another website?
如果另一個網站正在對我的ASP.NET MVC 2網站進行POST,如何捕獲它? 我需要對路線做任何事情嗎?
例如,另一個站點這樣做:
string url = "https://mvc2-site.com/TestReceive"; // that's my site's controller action
NameValueCollection inputs = new NameValueCollection();
inputs.Add("SessionId", "11111");
System.Net.WebClient Client = new WebClient();
byte[] result = Client.UploadValues(url, inputs);
如何在我的網站上收到該POST? 我努力了:
public ActionResult TestReceive(FormCollection fc) {} // doesn't get hit
public ActionResult TestReceive(string SessionId) {} // method gets hit but session id is null
public ActionResult TestReceive()
{
var param = ControllerContext.RouteData.Values["parameter"].ToString(); // Values["parameter"] is null
}
我不控制其他站點,它必須是POST(不是Web服務或其他任何東西)
作為另一種方式,它們將在10個變量附近進行POST,但有些是可選的,因此它們可能不在POST數據中。
[HttpPost]
public ActionResult TestReceive(string sessionId)
{
...
}
另外,由於在url中未指定控制器,因此您應確保包含此操作的控制器是路由中的默認控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.