WebAPI传递的post参数为null [英] WebAPI passed post parameters is null
本文介绍了WebAPI传递的post参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WebAPI 2进行测试,并且创建了以下控制器方法.
I'm testing with WebAPI 2 and I have created the following controller method.
// POST api/values
public string Post([FromBody] string value)
{
string returnValue = "Return: " + value ;
return returnValue;
}
当我用提琴手发布以下消息时,方法参数始终返回null.
When i'm posting the following message with fiddler the method parameter keep returning null.
POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 14
{value: "New"}
我已经尽我所能简化了代码,但仍然保持为空.
I have simplyfied my code already as much as i can but still it stays null.
我认为我忽略了一些非常简单的内容,但是我没有主意.有人可以帮我吗?
I think I'm overlooking something very simple but i'm out of ideas. Could someone please help me?
感谢桑德
推荐答案
如果要从Controller的Post方法中获取简单的String,请尝试仅发送以下内容:
If you're taking a simple String from your Controller's Post method, try sending just this:
POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 10
"MyString"
这篇关于WebAPI传递的post参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文