1

At times, when client sends an incorrect data to a API COntroller method, the request object become NULL when received. The primary cause of request object turning NULL could be client passing NULL value to a Non-Null property etc etc.

I would like to get that actual request object which client had sent so that I can get to know what client has passed and resolve the issue.

I receive my request object as:

HttpPost]
[Route("addQuote")]
public JsonResult AddQuote([FromBody]AddQuoteRequestModel quoteRequestModel)  { //Lines of code  }

Here, at times the quoteRequestModel object is received as NULL. I would like to capture the exact JSON client has passed in to this method.

Is there any way I can capture that?

Shiva Wahi
  • 433
  • 1
  • 5
  • 15
  • 1
    If you want handle "not valid" values then create request model which will have all values as nullable type. Then in controller you can convert it your actual request model with default values. – Fabio Jul 30 '18 at 04:59
  • Thanks Fabio but I don't find this a clean way. This would also make me change all request types and would invalidate my Model State Validations – Shiva Wahi Jul 30 '18 at 05:03
  • 1
    Possible duplicate of [How to read ASP.NET Core Response.Body?](https://stackoverflow.com/questions/43403941/how-to-read-asp-net-core-response-body) –  Jul 30 '18 at 17:50

0 Answers0