Search code examples
c#asp.netasp.net-web-apipostman.net-framework-version

.net framework c# web api, send username and password as string array in body from postman


I tried below code to read username/password from body, but all i am getting is 'object reference not set to an instance of an object' Code of API: postman image

[Route("api/login_test")]
[HttpGet]
public object login_test([FromBody] string[] Username_Password])
{
    string UsernameOrEmail_address, Password;
    UsernameOrEmail_address = Username_Password[0];
    Password = Username_Password[1];

    return UsernameOrEmail_address  + " " + Password;
}

Solution

  • by Changing the Http request it worked, replacing from HttpGet to HttpPost

    [Route("api/login_test")]
    [HttpPost]
    public object login_test([FromBody] string[] Username_Password])
    {
        string UsernameOrEmail_address, Password;
        UsernameOrEmail_address = Username_Password[0];
        Password = Username_Password[1];
    
        return UsernameOrEmail_address  + " " + Password;
    }