I have method which makes HTTP POST
I call this method with try catch like this
try
{
returnString = MakePost(gatewayEnpoint, data);
return returnString;
}
catch (System.Net.WebException ex)
{
var response = (HttpWebResponse)ex.Response;
if (response.StatusCode != HttpStatusCode.RequestTimeout || response.StatusCode != HttpStatusCode.InternalServerError)
{
return ex.Message.ToString();
}
}
but response
is always null.
How i can handle HTTP exceptions? i need status codes
thanks
There won't be a response if the client hasn't even managed to contact the server.
The cases in which there will be a response are for things like 404 status codes.
If you're never getting a response, then you're probably making some other mistake (e.g. trying to contact a server which doesn't exist).
I would strongly recommend that you don't return success and error cases in the same way as you're doing now, by the way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With