System.Net.HttpWebRequest.GetResponse Method

Returns a response from an Internet resource.


public override WebResponse GetResponse ()


A System.Net.WebResponse that contains the response from the Internet resource.


System.Net.ProtocolViolationExceptionThe HttpWebRequest.ContentLength property of the current instance is not set.

HttpWebRequest.Abort was previously called.


The timeout period for the request expired.


An error occurred while processing the request.


The HttpWebRequest.GetResponse method returns a System.Net.WebResponse object that contains the response from the Internet resource. The actual instance returned is an System.Net.HttpWebResponse, and can be typecast to that class to access HTTP-specific properties.

A System.Net.ProtocolViolationException is thrown in several cases when the properties set on the System.Net.HttpWebRequest class are conflicting. This exception occurs if an application sets the HttpWebRequest.ContentLength property and the HttpWebRequest.SendChunked property to true, and then sends an HTTP GET request. This exception occurs if an application tries to send chunked to a server that only supports HTTP 1.0 protocol, where this is not supported. This exception occurs if an application tries to send data without setting the HttpWebRequest.ContentLength property or the HttpWebRequest.SendChunked is false when buffering is disabled and on a keepalive connection (the HttpWebRequest.KeepAlive property is true).


You must call the HttpWebResponse.Close method to close the stream and release the connection. Failure to do so may cause your application to run out of connections.

When using the POST method, you must get the request stream, write the data to be posted, and close the stream. This method blocks waiting for content to post; if there is no time-out set and you do not provide content, the calling thread blocks indefinitely.


Multiple calls to HttpWebRequest.GetResponse return the same response object; the request is not reissued.


Your application cannot mix synchronous and asynchronous methods for a particular request. If you call the HttpWebRequest.GetRequestStream method, you must use the HttpWebRequest.GetResponse method to retrieve the response.


If a System.Net.WebException is thrown, use the WebException.Response and WebException.Status properties of the exception to determine the response from the server.


This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].


For security reasons, cookies are disabled by default. If you wish to use cookies, use the HttpWebRequest.CookieContainer property to enable cookies.


Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0,,