gpt4 book ai didi

c# - WebAPI 传递的 post 参数为空

转载 作者:太空狗 更新时间:2023-10-30 01:36:33 26 4
gpt4 key购买 nike

我正在使用 WebAPI 2 进行测试并创建了以下 Controller 方法。

// POST api/values
public string Post([FromBody] string value)
{
string returnValue = "Return: " + value ;
return returnValue;
}

当我使用 fiddler 发布以下消息时,方法参数一直返回 null。

POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 14

{value: "New"}

我已经尽可能多地简化了我的代码,但它仍然是空的。

我想我忽略了一些非常简单的事情,但我没有想法。有人可以帮助我吗?

谢谢桑德

最佳答案

如果您从 Controller 的 Post 方法中获取一个简单的字符串,请尝试仅发送以下内容:

POST http://localhost:50814/api/Values/ HTTP/1.1
Host: localhost:50814
Content-Type: application/json
Content-Length: 10

"MyString"

关于c# - WebAPI 传递的 post 参数为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21840280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com