我的身影,只是在打電話給應用程序的控制器A 通過必要的數據將用於工作所需要的
可以使用HttpClient在應用程序B調用中的應用的控制器行動A.
創建訂單和發送的順序到另一個MVC應用控制器(未測試)實施例。
private HttpClient client = new HttpClient();
public HomeController()
{
client.BaseAddress = new Uri("http://localhost:49277");
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
}
[HttpPost]
public ActionResult Insert(Order order)
{
HttpResponseMessage response = client.PostAsJsonAsync<Order>("/Order/Post" + $"/{order.OrderID}", order).Result;
return RedirectToAction("Index");
}
編輯
您可以使用 - UseDefaultCrendentials或直接通過credentials。
using (var handler = new HttpClientHandler {UseDefaultCredentials = true})
{
using (var client = new HttpClient(handler))
{
...
}
}
OR
var credentials = new NetworkCredential(userName, password);
using (var handler = new HttpClientHandler {Credentials = credentials })
{
using (var client = new HttpClient(handler))
{
...
}
}
聽起來像是你需要一個消息隊列(任何一種都行)。 –
@MattJohnson,謝謝馬特。這對我來說有點學習曲線,所以我會嘗試William的第一個。但是謝謝你向我介紹這個話題,因爲這絕對是展望未來的一些東西。 – eaglei22