简体   繁体   中英

.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: 邮递员形象

[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;
}

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM