How can I handle this request in my C# web API?
Request:
this._http.post(
this.url + 'api/Test',
{ auth: this.authClass},
{ headers: this.header }
).map(
(res) => res.json()
).subscribe(
(res) => {
console.log("VALUE RECEIVED: ", res);
})
AuthClass:
export class Auth{
username:string = "";
password:string = "";
}
I have a similar class in C# and need to figure out how to receive the class as a whole in C#.
I attempted:
[HttpPost]
public IHttpActionResult login(HttpRequestMessage request)
{
var jsonString = await request.Content.ReadAsStringAsync();
var model = JsonConvert.DeserializeObject<auth>(jsonString);
return Ok();
}
The issue is that it cannot parse the JSON to auth. The JSON string being sent currently looks like this.
{
"auth": {
"username": "admin",
"password": "admin1"
}
}
If it's just:
{
"username": "admin",
"password": "admin1"
}
then it works without any issues. But I need it to consume the first JSON example.