項目需求,提供一個無參數的post請求給第三方,對方把數據以json格式通過raw傳遞過來
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Http; using WebApplication5.Helper; namespace WebApplication5.Controllers { public class VIIDController : ApiController { [HttpPost] public string DispositionNotifications() { string result = ""; try { Stream postData = HttpContext.Current.Request.InputStream; StreamReader sRead = new StreamReader(postData); string postContent = sRead.ReadToEnd(); sRead.Close(); Log4NetHelper.Info($"【獲取數據】" + postContent); result = "success"; } catch (Exception ex) { result = $"error:{ex.Message.ToString()}"; } return result; } [HttpGet] public string DispositionNotifications2() { return "value"; } } }
后台調用和普通調用一樣