Skip to main content
edited tags
Link
Mr. Boy
  • 64.5k
  • 104
  • 362
  • 662
Source Link
Mr. Boy
  • 64.5k
  • 104
  • 362
  • 662

BadRequest response string is wrapped in additional quotes

In my ASP.Net REST controller I do the following:

return BadRequest("A problem happened!"); 

When calling this over HTTP I get the message as follows:

HttpResponseMessage response = await _httpClient.GetAsync(url); if (!response.IsSuccessStatusCode) { var errorMessage = await response.Content.ReadAsStringAsync(); 

But the value of the errorMessage is:

"\"A problem happened!\"" 

When I run through PostMan it doesn't include the quote marks even in the raw output view so I'm not sure if they are being added on for some reason, but I would rather avoid having to manually strip them.

I based my work on this other question where nobody seemed to have this issue: BadRequest custom error message not returned to client?