post接收raw傳遞數據


項目需求,提供一個無參數的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";
        }
    }
}

 

后台調用和普通調用一樣

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM