ASP .NET Web API-在POST方法中获取纯json [英] ASP .NET Web API - Get plain json in POST method

查看:103
本文介绍了ASP .NET Web API-在POST方法中获取纯json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web API控制器,该控制器具有POST方法,该方法从请求主体接收数据,并且它所做的全部就是将其发送到另一个Web服务,因此不需要反序列化数据.如何禁用由Web API完成的自动反序列化?

I have a Web API controller that has a POST method which receives data from the request body, and all it does is send it to another web service, so deserializing the data is not necessary. How can I disable the auto deserialization done by the Web API?

public IHttpActionResult Post([FromBody]string data)
{
 //Post with http client...

}

带有此签名的数据以null到达.

The data arrives as null with this signature.

推荐答案

检查此内容:

public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
    var data = await request.Content.ReadAsStringAsync();
    // do stuff with the content
}

有关解决方案的更多信息: http://bizcoder.com/posting-raw-json-to-web-api

More about the solution: http://bizcoder.com/posting-raw-json-to-web-api

这篇关于ASP .NET Web API-在POST方法中获取纯json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆