【发布时间】:2015-06-25 12:50:09
【问题描述】:
我的 Web API 中有以下方法:
[AcceptVerbs("POST")]
public bool MoveFile([FromBody] FileUserModel model)
{
if (model.domain == "abc")
{
return true;
}
return false;
}
FileUserModel 定义为:
public class FileUserModel
{
public string domain { get; set; }
public string username { get; set; }
public string password { get; set; }
public string fileName { get; set; }
}
我试图通过 Fiddler 调用它,但每当我这样做时,模型总是设置为 null。在 Fiddler 中,我已将作曲家发送给使用 POST,该 url 在那里并且正确,因为 Visual Studio 中的调试器在调用时会中断。我设置的请求为:
User-Agent: Fiddler
Host: localhost:46992
Content-Length: 127
Content-Type: application/json
请求正文为:
"{
"domain": "dcas"
"username": "sample string 2",
"password": "sample string 3",
"fileName": "sample string 4"
}"
但每当我在调试器遇到断点时运行作曲家时,它总是显示模型为空。
【问题讨论】:
-
请求正文是否有您在此处发布的双引号?
-
这是一个错字,在 domain: dcas 之后没有“,”?
-
您是否尝试将一项测试的输入参数类型从 FileUserModel 更改为字符串?
-
尝试我在以下答案中提供的解决方案
-
那么你需要删除那些引号,它们是不需要的。
标签: c# asp.net json asp.net-web-api fiddler