项目需求,提供一个无参数的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";
        }
    }
}

 

后台调用和普通调用一样

 

posted on 2020-07-14 10:56  红磨坊后的白桦树  阅读(1543)  评论(0编辑  收藏  举报