FromBody 未绑定字符串参数

编程入门 行业动态 更新时间:2024-10-22 17:37:07
本文介绍了FromBody 未绑定字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个类似于 ASP.NET 的问题MVC 4 RC Web API 参数绑定问题,但我正在尝试使用 [FromBody] 属性来解决它.

I have an issue similar to ASP.NET MVC 4 RC Web API Parameter Binding Issue, but I'm trying to solve it by using the [FromBody] attribute.

Fiddler 报告以下请求(不包括 User Agent String 等无关位)

Fiddler reports the following request (excluding irrelevant bits like User Agent String)

PUT localhost:82/api/account/shoppinglistitems HTTP/1.1 Host: localhost:82 Connection: keep-alive Content-Length: 11 Origin: localhost:3000 Content-Type: application/x-www-form-urlencoded Accept: application/json, text/javascript, */*; q=0.01 query=apple

我的控制器操作是

[HttpPut] public ShoppingListItemWebModel CreateShoppingListItem([FromBody]string query) { // query is null }

我可以将参数包装在复杂类型中,但这似乎是解决问题的一种技巧.或者我可以将查询放在 URI 中,但这不符合 API 其余部分的模式.可以这样做吗?如果是这样,我的错误在哪里?

I could wrap the parameter in a complex type, but that seems like a hack to fix the issue. Or I could put the query in the URI, but that doesn't fit the pattern of the rest of the API. Is it possible to do it this way? If so, where is my mistake?

推荐答案

更改您的要求

PUT localhost:82/api/account/shoppinglistitems HTTP/1.1 Host: localhost:82 Connection: keep-alive Content-Length: 11 Origin: localhost:3000 Content-Type: application/x-www-form-urlencoded Accept: application/json, text/javascript, */*; q=0.01 =apple

注意缺少查询"

更多推荐

FromBody 未绑定字符串参数

本文发布于:2023-10-29 03:54:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   绑定   参数   FromBody

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!