FromBody没有约束力字符串参数

编程入门 行业动态 更新时间:2024-10-22 21:26:32
本文介绍了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 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

我的控制器动作

My controller action is

[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

注意缺少查询

notice the lack of "query"

更多推荐

FromBody没有约束力字符串参数

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

发布评论

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

>www.elefans.com

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