I have the following method in my Web API:
[AcceptVerbs("POST")]
public bool MoveFile([FromBody] FileUserModel model)
{
if (model.domain == "abc")
{
return true;
}
return false;
}
The FileUserModel
is defined as:
public class FileUserModel
{
public string domain { get; set; }
public string username { get; set; }
public string password { get; set; }
public string fileName { get; set; }
}
I'm trying to call this through Fiddler but whenever I do the model is always set to null. In Fiddler I've sent the composer to use POST
, the url is there and correct as the debugger in Visual Studio breaks when called. The Request I've setup as:
User-Agent: Fiddler
Host: localhost:46992
Content-Length: 127
Content-Type: application/json
The Request Body as:
"{
"domain": "dcas"
"username": "sample string 2",
"password": "sample string 3",
"fileName": "sample string 4"
}"
But whenever I run the composer when the debugger hits the breakpoint it always shows model is null.
The problem you have is you are posting the JSON data with surrounding double quotes. Remove them and it should work.
Also fix the missing comma:
{
"domain": "dcas",
"username": "sample string 2",
"password": "sample string 3",
"fileName": "sample string 4"
}