Search code examples
apihttpresponsemessage

Reading HttpResponse


I am capturing a HttpResponseMessage using C#. I see the Headers and Content easily using C# and Telerik Fiddler. How do I get to the Json Message ={"error_message":"Unable to find Category 130"}? This is the response that is being returned from a third party vendor

HttpResponse:

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Cache-control: no-cache="set-cookie"
Content-Type: application/xxxxxxxx;version=1.0
Date: Thu, 23 Jan 2020 20:14:18 GMT
Server: Apache/2.4.7 (Ubuntu)
Set-Cookie: AWSELB=B951170B0258C274F4328378523700A29FEEC6BAABF6103540B7038DA196F54B6874B912614AC1E0CD2E8767C34FC2E6F1E24E6532E90C88E5E4413E3E7A09EFA6074CFAC1;PATH=/;MAX-AGE=300
Content-Length: 47
Connection: keep-alive

{"error_message":"Unable to find Category 130"}

Solution

  • So how I went about solving this issue with Http Response being returned with statuscode of 200 but and error message in the content, is to include looking for a error in the Response.Content.ReadAsStringAsync().Result