0

I am using C# WebClient to get a server response and i get this exception message :

The remote server returned an error: (403) Forbidden.

this is right page response code is 403 but there is additional response message i need to read. this response message is the same i get when i access the server from a web browser.

The first image is showing HTTP headers in chrome. and the second one shows the response.

what i am asking for is how to get this text/plain response message ?

http headers in chrome


http response

T4mer
  • 430
  • 2
  • 7
  • 22

1 Answers1

1

Catch the WebException and read its Response property:

try
{
    request.GetResponse();
}
catch (WebException e)
{
    if (e.Response != null)
        return getResponseBody(e.Response);
    else
        throw;
}
python_kaa
  • 1,034
  • 13
  • 27