I have .NET API Example:
[Route("[controller]")]
[ApiController]
public class UserController : ControllerBase
{
[HttpGet("GetUser")]
public ActionResult GetUserDetails(User userReq)
{
var response = service.GetUser(userReq);
return Ok(response);
}
}
And User class Example:
public class User
{
public int? ID { get; set; }
public string Name { get; set; }
public int? Age { get; set; }
public char? Gender { get; set; }
public string Email { get; set; }
public int? Phone { get; set; }
}
I am calling the API in below way through axios in React, Example:
axios.get(String(APIUrls.GetUser),
{
params: {
ID: null,
Name: null,
Age: null,
Gender: null,
Email: null,
Phone: null
},
}).then(response => {
console.log(response.data);
})
.catch((err) => {
console.log(err);
});
I am able to get response through postman, but when I try from my application its not working.
Error:
Status Code: 415
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"xxxxxxxxxxxx:00000005"}