ASP.NET的WebAPI没有收到数据后 [英] ASP.NET WebApi not receiving post data

查看:212
本文介绍了ASP.NET的WebAPI没有收到数据后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要接收使用的WebAPI一些字符串和二进制数据。我创建了一个控制器是这样的:

I need to receive some string and binary data using WebApi. I have created a controller this way:

    [HttpPost]
    public void Post(byte[] buffer)
    {
        // Some code goes here
    }

这里的routtings:

Here's the routtings:

    routes.MapHttpRoute(
        name: "CuscarD95B",
        routeTemplate: "D95B/{controller}",
        defaults: new { buffer = RouteParameter.Optional },
        constraints: new { controller = @"Cuscar" }

现在,当我尝试发布一些数据,缓冲器总是字节[0](零长度数组)。没有数据被传递到控制器。

Now when I try to post some data, buffer is always byte[0] (zero length array). No data is being passed to the controller.

任何帮助将是AP preciated。

Any help would be appreciated.

感谢。

推荐答案

我找到了解决办法<一href="http://myadventuresincoding.word$p$pss.com/2012/06/19/c-supporting-textplain-in-an-mvc-4-rc-web-api-application/"相对=nofollow>此处。 看来我们需要创建自定义MediaTypeFormatter实现基本类型反序列化。

I found the solution here. Looks like we need to create custom MediaTypeFormatter to achieve primitive type deserialization.

这篇关于ASP.NET的WebAPI没有收到数据后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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