in asp.net core web api i have a POST method that get username and password in FormUrlEncodedContent format from client. But the "entry" parameter is null.
how can i access the username and password in Login method in web api ?
here is my code:
client:
public async Task<string> login2(string command , string username , string password)
{
string exist = string.Empty;
FormUrlEncodedContent dataForm = new FormUrlEncodedContent(new[] {
new KeyValuePair<string,string>("username",username),
new KeyValuePair<string, string>("password",password)
});
var resp = await http.PostAsync(command,dataForm);
exist = await resp.Content.ReadAsStringAsync();
return exist;
}
server :
public IActionResult Login([FromForm] string entry)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
Console.WriteLine(entry);
return Ok(entry);
}