Night Monger
Night Monger

Reputation: 780

Web API post Body object is null

I have a Web api method like this

        [HttpPost]
        public IHttpActionResult Login(ILogin request)
        {
             // do stuff 
        }

My Login object is

 public interface ILogin 
    {
        string UserName { get; set; }
        string Password { get; set; }
    }

I am trying to call from fiddler with the following details

url - myapi.com/login

Request Body

  {
    "UserName": "[email protected]",
    "Password": "adfdfdf"
  }

I tried various combinations of request body - but whenever i debug - the ILogin request is always null. What am i doing wrong?

Upvotes: 0

Views: 456

Answers (1)

Thiago Custodio
Thiago Custodio

Reputation: 18387

You can't instantiate an interface. Your webapi should expect a class that implements the ILogin interface.

Upvotes: 2

Related Questions