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