需求是提供一个WEBAPI给对方平台调用,对方平台只能按照POST方式,参数放在BODY中,格式是Text或Text/plain。效果如下图
但是在调试过程中,发现但是string无法接收Text或Text/plain,一直是NULL。经查询资料,发现普通的webapi 是不支持这个请求的。需要进行格式定义,借鉴https://www.cnblogs.com/chenhuzi/p/6123393.html的类。完成调试。
新增一个类,类名为PlainTextTypeFormatter
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Threading.Tasks;
namespace WebApi.Common
{
public class PlainTextTypeFormatter : MediaTypeFormatter
{
public PlainTex