Introduction
This post explains the 'The Request is Invalid' error from the ASP.NET Web API.
The Request Is Invalid Error From ASP.NET Web API
The Request Is Invalid Error From ASP.NET Web API
Error Reason:
  • Forgot to define routing.
  • Same method name.
Solved this error using Routing on the method level.
  1. [HttpGet]
  2. public List<string> GetAllString()
  3. {
  4. return new List<string> {"ABC","XYZ" };
  5. }
  6. [HttpGet]
  7. [Route("NumberList")]
  8. public List<int> GetAllNumbers()
  9. {
  10. return new List<int> { 122, 555 };
  11. }
  12. [HttpGet]
  13. [Route("api/numberapi/NumberList")]
  14. public List<int> GetAllEvenNumber()
  15. {
  16. return new List<int> { 22, 44,66 };
  17. }
Problem Solved
http://localhost:50297/numberlist
The Request Is Invalid Error From ASP.NET Web API
http://localhost:50297/api/numberapi/numberlist
The Request Is Invalid Error From ASP.NET Web API
NOTE
Some times the above solution will not fit or suit as per your current scenario. Please go through the following external links for solutions.
Other Links: