System.Net.HttpWebRequest Class

public class HttpWebRequest : WebRequest

Base Types

Object
  MarshalByRefObject
    WebRequest
      HttpWebRequest

Assembly

System

Library

Networking

Summary

Provides an HTTP-specific implementation of the WebRequest class.

Description

This class implements properties and methods defined in WebRequest and provides additional properties and methods that enable the user to interact directly with servers using the Hypertext Transfer Protocol (HTTP).

[Note: Instances of this class are automatically created by the WebRequest class. For example, an instance of HttpWebRequest is created when the System.Net.WebRequest.Create(System.Uri,System.Boolean) method is called and a Uniform Resource Identifier (URI) beginning with http:// is specified. It is expected that an instance of this class will be constructed for every request made to the server. For example, after a call to System.Net.HttpWebRequest.Abort cancels an asynchronous operation, a call to System.Net.HttpWebRequest.GetRequestStream causes a WebException to be thrown.

Requests can be sent synchronously or asynchronously. The System.Net.HttpWebRequest.GetResponse method sends a request to a server synchronously and returns a HttpWebResponse instance containing the response. An asynchronous request for a resource is sent using the System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object) and System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) methods.

Request data is sent using a request stream. The System.Net.HttpWebRequest.GetRequestStream , System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object), and System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) methods return a Stream instance used to send data.

When errors occur while accessing an Internet resource, the HttpWebRequest class throws a WebException , and the System.Net.WebException.Status property that indicates the source of the error. When System.Net.WebException.Status is System.Net.WebExceptionStatus.ProtocolError, the System.Net.WebException.Response property contains the HttpWebResponse received from the Internet resource.

Certain HTTP headers are protected; the user cannot set them directly in the header collection obtained from the System.Net.HttpWebRequest.Headers property. Instead, these headers are set using the associated properties of a HttpWebRequest instance, or are set by the system. The following table describes how each protected header is set.

HeaderSet by
AcceptSystem.Net.HttpWebRequest.Accept
ConnectionSystem.Net.HttpWebRequest.Connection

System.Net.HttpWebRequest.KeepAlive

Content-LengthSystem.Net.HttpWebRequest.ContentLength
Content-TypeSystem.Net.HttpWebRequest.ContentType
ExpectSystem.Net.HttpWebRequest.Expect
DateSet to current date by the system.
Host Set to current host by the system.
if-Modified-sinceSystem.Net.HttpWebRequest.IfModifiedSince
RangeSystem.Net.HttpWebRequest.AddRange(System.Int32,System.Int32)
RefererSystem.Net.HttpWebRequest.Referer
Transfer-EncodingSystem.Net.HttpWebRequest.TransferEncoding

System.Net.HttpWebRequest.SendChunked

User-AgentSystem.Net.HttpWebRequest.UserAgent
]

See Also

System.Net Namespace

Members

HttpWebRequest Methods

HttpWebRequest.Abort Method
HttpWebRequest.AddRange(System.String, int) Method
HttpWebRequest.AddRange(System.String, int, int) Method
HttpWebRequest.AddRange(int) Method
HttpWebRequest.AddRange(int, int) Method
HttpWebRequest.BeginGetRequestStream Method
HttpWebRequest.BeginGetResponse Method
HttpWebRequest.EndGetRequestStream Method
HttpWebRequest.EndGetResponse Method
HttpWebRequest.GetHashCode Method
HttpWebRequest.GetRequestStream Method
HttpWebRequest.GetResponse Method

HttpWebRequest Properties

HttpWebRequest.Accept Property
HttpWebRequest.Address Property
HttpWebRequest.AllowAutoRedirect Property
HttpWebRequest.AllowWriteStreamBuffering Property
HttpWebRequest.Connection Property
HttpWebRequest.ConnectionGroupName Property
HttpWebRequest.ContentLength Property
HttpWebRequest.ContentType Property
HttpWebRequest.ContinueDelegate Property
HttpWebRequest.Credentials Property
HttpWebRequest.Expect Property
HttpWebRequest.HaveResponse Property
HttpWebRequest.Headers Property
HttpWebRequest.IfModifiedSince Property
HttpWebRequest.KeepAlive Property
HttpWebRequest.MaximumAutomaticRedirections Property
HttpWebRequest.MediaType Property
HttpWebRequest.Method Property
HttpWebRequest.Pipelined Property
HttpWebRequest.PreAuthenticate Property
HttpWebRequest.ProtocolVersion Property
HttpWebRequest.Proxy Property
HttpWebRequest.Referer Property
HttpWebRequest.RequestUri Property
HttpWebRequest.SendChunked Property
HttpWebRequest.ServicePoint Property
HttpWebRequest.Timeout Property
HttpWebRequest.TransferEncoding Property
HttpWebRequest.UserAgent Property


HttpWebRequest.Abort Method

public override void Abort();

Summary

Cancels an asynchronous operation.

Description

System.Net.HttpWebRequest.Abort cancels any pending asynchronous operation. After this method is called, calling System.Net.HttpWebRequest.GetResponse, System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object), System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult), System.Net.HttpWebRequest.GetRequestStream, System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object), or System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) will throw a WebException with System.Net.WebException.Status set to System.Net.WebExceptionStatus.RequestCanceled .

[Note: If no pending request exists, calling this method does not cause an exception to be thrown.

This method overrides System.Net.WebRequest.Abort.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AddRange(System.String, int) Method

public void AddRange(string rangeSpecifier, int range);

Summary

Adds a HTTP Range header to the current request for a specific range from the beginning or end of the requested data.

Parameters

rangeSpecifier
A String that contains the description of the range.
range
A Int32 that designates the starting or ending point of the range. If this value is positive, the range is from the beginning of the data to range. If this value is negative, the range is from range to the end of the data.

Exceptions

Exception TypeCondition
ArgumentNullExceptionrangeSpecifier is null .
ArgumentExceptionrangeSpecifier is invalid.
InvalidOperationExceptionThe range header could not be added.

Description

[Note: The HTTP Range header specifies either a single range of bytes or a set of byte ranges in an entity-body to be returned. If the server accessed by the current instance supports the use of this header, this allows for the partial retrieval of the entity due to, for example, the entity being particularly large or there having been a failed transfer of data.

For more information on the HTTP Range header, see Section 14.35 of RFC 2616.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AddRange(System.String, int, int) Method

public void AddRange(string rangeSpecifier, int from, int to);

Summary

Adds a HTTP Range header to the current instance for a specified range.

Parameters

rangeSpecifier
A String that contains the description of the range.
from
A Int32 designating the position at which to start sending data.
to
A Int32 designating the position at which to stop sending data.

Exceptions

Exception TypeCondition
ArgumentNullExceptionrangeSpecifier is null .
ArgumentOutOfRangeExceptionfrom < 0.

-or-

to < 0.

-or-

from > to .

ArgumentExceptionrangeSpecifier is invalid.
InvalidOperationExceptionThe range header could not be added.

Description

[Note: The HTTP Range header specifies either a single range of bytes or a set of byte ranges in an entity-body to be returned. If the server accessed by the current instance supports the use of this header, this allows for the partial retrieval of the entity due to, for example, the entity being particularly large or there having been a failed transfer of data.

For more information on the HTTP Range header, see Section 14.35 of IETF RFC 2616.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AddRange(int) Method

public void AddRange(int range);

Summary

Adds a HTTP Range header to the current instance for a specific range from the beginning or end of the requested data.

Parameters

range
A Int32 that specifies the starting or ending point of the range. If this value is positive, the range is from the beginning of the data to range. If this value is negative, the range is from range to the end of the data.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe range header could not be added.

Description

This method is equivalent to System.Net.HttpWebRequest.AddRange(System.Int32,System.Int32)("bytes", range).

[Note: The HTTP Range header specifies either a single range of bytes or a set of byte ranges in an entity-body to be returned. If the server accessed by the current instance supports the use of this header, this allows for the partial retrieval of the entity due to, for example, the entity being particularly large or there having been a failed transfer of data.

For more information on the HTTP Range header, see Section 14.35 of RFC 2616.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AddRange(int, int) Method

public void AddRange(int from, int to);

Summary

Adds a HTTP Range header to the current instance for a specified range.

Parameters

from
A Int32 indicating the starting byte position of the entity-body data to be returned.
to
A Int32 indicating the last byte.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionfrom < 0.

-or-

to < 0.

-or-

from > to .

InvalidOperationExceptionThe range header could not be added.

Description

This method is equivalent to System.Net.HttpWebRequest.AddRange(System.Int32,System.Int32)("bytes", from, to).

[Note: The HTTP Range header specifies either a single range of bytes or a set of byte ranges in an entity-body to be returned. If the server accessed by the current instance supports the use of this header, this allows for the partial retrieval of the entity due to, for example, the entity being particularly large or there having been a failed transfer of data.

For more information on the HTTP Range header, see Section 14.35 of RFC 2616.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.BeginGetRequestStream Method

public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);

Summary

Begins an asynchronous request for a stream in which to write data to be sent in the current instance.

Parameters

callback
A AsyncCallback delegate to be called when the stream is available. Can be null .
state
A Object containing state information for the asynchronous request. Can be null .

Return Value

A IAsyncResult that contains information about the asynchronous operation.

Exceptions

Exception TypeCondition
InvalidOperationExceptionThe stream is being used by a previous call to System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) .

-or-

No writeable stream is available.

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

-or-

The System.Net.HttpWebRequest.Method property of the current instance is "GET" or "HEAD".

Description

This method starts an asynchronous operation. To get the request stream, call the System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) method and specify the IAsyncResult object returned by this method. [Note: The System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) method should be called exactly once for each call to System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object).]

If the callback parameter is not null , the method(s) referenced by callback are invoked when the asynchronous operation completes. The IAsyncResult object returned by this method is passed as the argument to the method(s) referenced by callback .

The state parameter can be any object that the caller wishes to have available for the duration of the asynchronous operation. This object is available via the System.IAsyncResult.AsyncState property of the object returned by this method.

The value of the System.Net.HttpWebRequest.ContentLength property of the current instance is required to be set prior to calling this method.

[Note: The method(s) invoked by the callback delegate can call the System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) method to retrieve the stream.

This method is the asynchronous version of the System.Net.HttpWebRequest.GetRequestStream method.

This method overrides System.Net.WebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) .

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.BeginGetResponse Method

public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state);

Summary

Begins sending the current HTTP request asynchronously.

Parameters

callback
A AsyncCallback delegate to be called when the stream is available. Can be null .
state
A Object containing state information for the asynchronous request. Can be null .

Return Value

A IAsyncResult that contains information about the asynchronous operation.

Exceptions

Exception TypeCondition
InvalidOperationExceptionSystem.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object) or System.Net.HttpWebRequest.GetResponse was previously called on this instance.
ProtocolViolationExceptionThe System.Net.HttpWebRequest.ContentLength property of the current instance has not been set.
WebExceptionSystem.Net.HttpWebRequest.Abort was previously called.

Description

This method starts an asynchronous operation. To get the response, call the System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) method and specify the IAsyncResult object returned by this method. [Note: The System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) method should be called exactly once for each call to System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object).]

If the callback parameter is not null , the method referenced by callback is invoked when the asynchronous operation completes. The IAsyncResult object returned by this method is passed as the argument to the method referenced by callback.

The state parameter can be any object that the caller wishes to have available for the duration of the asynchronous operation. This object is available via the System.IAsyncResult.AsyncState property of the object returned by this method.

[Note: The method(s) invoked by the callback delegate can call the System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) method to retrieve the response.

This method is the asynchronous version of the System.Net.HttpWebRequest.GetResponse method.

This method overrides System.Net.WebRequest.BeginGetResponse(System.AsyncCallback,System.Object).

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.EndGetRequestStream Method

public override Stream EndGetRequestStream(IAsyncResult asyncResult);

Summary

Completes an asynchronous request for a stream that was started by the System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) method.

Parameters

asyncResult
The IAsyncResult object that holds the state information for the asynchronous operation.

Return Value

A Stream to write request data to.

Exceptions

Exception TypeCondition
ArgumentNullExceptionasyncResult is null .
ArgumentExceptionasyncResult was not returned by the current instance from a call to System.Net.WebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object).
InvalidOperationException This method was called previously using asyncResult.

-or-

No stream is available.

WebExceptionSystem.Net.HttpWebRequest.Abort was previously called.

-or-

An error occurred while processing the request.

Description

[Note: The caller is responsible for calling the System.IO.Stream.Close method to close the stream.

This method overrides System.Net.WebRequest.EndGetRequestStream(System.IAsyncResult).

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.EndGetResponse Method

public override WebResponse EndGetResponse(IAsyncResult asyncResult);

Summary

Returns a WebResponse that contains a response to the specified pending Internet request.

Parameters

asyncResult
The IAsyncResult object that hold the state information for the asynchronous operation.

Return Value

A WebResponse that contains a response to the Internet request referenced by asyncResult .

Exceptions

Exception TypeCondition
ArgumentNullExceptionasyncResult is null .
ArgumentExceptionasyncResult was not returned by the current instance from a call to System.Net.WebRequest.BeginGetResponse(System.AsyncCallback,System.Object).
InvalidOperationException This method was called previously using asyncResult.

-or-

The System.Net.HttpWebRequest.ContentLength property of the current instance is greater than 0 but the data has not been written to the request stream.

WebExceptionSystem.Net.HttpWebRequest.Abort was previously called.

-or-

An error occurred while processing the request.

Description

[Note: This method completes an asynchronous request for an Internet resource that was started by calling System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object).

This method overrides System.Net.WebRequest.EndGetResponse(System.IAsyncResult).

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

Return Value

A Int32 containing the hash code for the current instance.

Description

The algorithm used to generate the hash code is unspecified.

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.GetRequestStream Method

public override Stream GetRequestStream();

Summary

Returns a Stream for writing data to the Internet resource requested by the current instance.

Return Value

A Stream for writing data to an Internet resource requested by the current instance.

Exceptions

Exception TypeCondition
ProtocolViolationExceptionThe System.Net.HttpWebRequest.Method property of the current instance is "GET" or "HEAD".

-or-

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

InvalidOperationExceptionThe System.Net.HttpWebRequest.GetRequestStream method was called more than once.

-or-

No writeable stream is available.

WebExceptionSystem.Net.HttpWebRequest.Abort was previously called.

-or-

The timeout period for the request expired.

-or-

An error occurred while processing the request.

Description

The value of the System.Net.HttpWebRequest.ContentLength property is required to be set before writing data to the stream.

[Note: This method returns a stream to use to send data for the HttpWebRequest. Once the Stream instance has been returned, data can be sent with the HttpWebRequest by using the System.IO.Stream.Write(System.Byte[],System.Int32,System.Int32) method.

Call the System.IO.Stream.Close method to close the stream and release the connection for reuse. Failure to close the stream might cause the application to run out of connections.

This method overrides System.Net.WebRequest.GetRequestStream.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.GetResponse Method

public override WebResponse GetResponse();

Summary

Returns a response to an Internet request.

Return Value

A WebResponse containing the response from the Internet resource requested by the current instance.

Exceptions

Exception TypeCondition
ProtocolViolationExceptionThe System.Net.HttpWebRequest.ContentLength property of the current instance is not set.
WebExceptionSystem.Net.HttpWebRequest.Abort was previously called.

-or-

The timeout period for the request expired.

-or-

An error occurred while processing the request.

Description

[Note: This method returns a WebResponse instance containing the response from the Internet resource requested by the current instance. The actual instance returned is an instance of HttpWebResponse , and can be typecast to that class to access HTTP-specific properties.

This method overrides System.Net.WebRequest.GetResponse .

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Accept Property

public string Accept { get; set; }

Summary

Gets or sets a String containing the value of the HTTP Accept header.

Property Value

A String containing the value of the HTTP Accept header. The default value of this property is null .

Description

[Note: For additional information see section 14.1 of IETF RFC 2616 - HTTP/1.1.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Address Property

public Uri Address { get; }

Summary

Gets the URI that responds to the current request.

Property Value

A Uri identifying the Internet resource that responds to the current request. The default is the URI used by the System.Net.WebRequest.Create(System.Uri,System.Boolean) method to initialize the current instance.

Description

This property is read-only.

The value of this property is set to the URI that is the source of the response after all redirections are complete.

[Note: The URI of the original request is kept in the System.Net.HttpWebRequest.RequestUri property.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AllowAutoRedirect Property

public bool AllowAutoRedirect { get; set; }

Summary

Gets or sets a Boolean value that indicates whether the current request will follow redirection responses.

Property Value

true if the current request will automatically follow redirection responses from the Internet resource; otherwise false . The default value is true .

Description

[Note: Set System.Net.HttpWebRequest.AllowAutoRedirect to true to allow the current request to automatically follow HTTP redirection headers to the new location of a resource.

The maximum number of redirections to follow is set by the System.Net.HttpWebRequest.MaximumAutomaticRedirections property.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.AllowWriteStreamBuffering Property

public bool AllowWriteStreamBuffering { get; set; }

Summary

Gets or sets a Boolean value that indicates whether to buffer the data sent to the Internet resource requested by the current instance.

Property Value

true to enable buffering of the data sent to the Internet resource requested by the current instance; false to disable buffering. The default is true .

Description

[Note: When System.Net.HttpWebRequest.AllowWriteStreamBuffering is true , the data is buffered in memory so it is ready to be resent in the event of redirections or authentication requests.

Depending on available memory, setting System.Net.HttpWebRequest.AllowWriteStreamBuffering as true might impact system performance when uploading large amounts of data.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Connection Property

public string Connection { get; set; }

Summary

Gets or sets the value of the Connection HTTP header.

Property Value

A String containing the value of the Connection HTTP header. The default value is null .

Exceptions

Exception TypeCondition
ArgumentExceptionThe value of System.Net.HttpWebRequest.Connection is set to "Keep-alive" or "Close". This value is case insensitive.

Description

The current request sends the System.Net.HttpWebRequest.Connection property to the Internet resource as the Connection HTTP header.

[Note: If System.Net.HttpWebRequest.KeepAlive is true , the value "Keep-alive" is appended to the end of the Connection header.

For additional information see section 14.10 of IETF RFC 2616 - HTTP/1.1.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ConnectionGroupName Property

public override string ConnectionGroupName { get; set; }

Summary

Gets or sets the name of the connection group for the current instance.

Property Value

A String that contains the name of the connection group for the current instance. The default value is null .

Description

[Note: The System.Net.HttpWebRequest.ConnectionGroupName property enables a request to be associated with a connection group. This is useful when an application makes requests to one server for different users, such as a Web site that retrieves customer information from a database server.

Each connection group creates additional connections for a server. This might result in exceeding System.Net.ServicePoint.ConnectionLimit for that server.

This property overrides System.Net.WebRequest.ConnectionGroupName.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ContentLength Property

public override long ContentLength { get; set; }

Summary

Gets or sets the Content-length HTTP header.

Property Value

A Int64 value that specifies the number of bytes of data to send to the Internet resource. The default is -1, which indicates that this value has not been set.

Exceptions

Exception TypeCondition
InvalidOperationExceptionData has already been written to the request stream.
ArgumentOutOfRangeExceptionA value less than zero is specified for a set operation.

Description

The System.Net.HttpWebRequest.ContentLength property contains the value to send as the Content-length HTTP header of the request.

Any value other than -1 in the System.Net.HttpWebRequest.ContentLength property indicates that the request will upload data; only methods that upload data are allowed in the System.Net.HttpWebRequest.Method property.

This property is required to be set prior to writing data to the request data stream. Once the System.Net.HttpWebRequest.ContentLength property is set to a value, that number of bytes is required to be written to the request data stream. [Note: Get the request data stream by calling System.Net.HttpWebRequest.GetRequestStream , or System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) and System.Net.HttpWebRequest.EndGetRequestStream(System.IAsyncResult) .]

[Note: For additional information see section 14.13 of IETF RFC 2616 - HTTP/1.1.

This property overrides System.Net.WebRequest.ContentLength.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ContentType Property

public override string ContentType { get; set; }

Summary

Gets or sets the value of the Content-type HTTP header of the current instance.

Property Value

The value of the Content-type HTTP header of the current instance. The default value is null .

Description

The System.Net.HttpWebRequest.ContentType property contains the media type of the current instance. Values assigned to the System.Net.HttpWebRequest.ContentType property replace any existing contents when the request sends the Content-type HTTP header.

[Note: To clear the Content-type HTTP header, set the System.Net.HttpWebRequest.ContentType property to null .

For additional information see section 14.17 of IETF RFC 2616 - HTTP/1.1.

This property overrides System.Net.WebRequest.ContentType.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ContinueDelegate Property

public HttpContinueDelegate ContinueDelegate { get; set; }

Summary

Gets or sets the delegate method whose methods are invoked when an HTTP 100-continue response is received by the current instance.

Property Value

A HttpContinueDelegate that references the methods that are invoked when an HTTP Continue response is received. The default value is null .

Description

[Note: This delegate is useful to display the status of responses received by the current instance.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Credentials Property

public override ICredentials Credentials { get; set; }

Summary

Gets or sets the credentials used for authenticating the current request.

Property Value

A ICredentials object containing the authentication credentials associated with the current instance. The default is null .

Description

[Note: The System.Net.HttpWebRequest.Credentials property contains authentication information to identify the client making the request. The System.Net.HttpWebRequest.Credentials property can be either an instance of NetworkCredential, in which case the user, password, and domain information contained in the NetworkCredential instance is used to authenticate the request, or it can be an instance of CredentialCache, in which case the uniform resource identifier (URI) of the request is used to determine the user, password, and domain information to use to authenticate the request.

This property overrides System.Net.WebRequest.Credentials .

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Expect Property

public string Expect { get; set; }

Summary

Gets or sets the value of the HTTP Expect header.

Property Value

A String that contains the contents of the HTTP Expect header. The default value is null .

Exceptions

Exception TypeCondition
ArgumentExceptionThe value specified for a set operation is "100-continue". This value is case insensitive.

Description

[Note: By default, System.Net.HttpWebRequest.Expect is null . Other values can be added to the list that System.Net.HttpWebRequest.Expect maintains, or all values except "100-continue" can be deleted from the list by setting System.Net.HttpWebRequest.Expect to null .

For additional information see section 14.20 of IETF RFC 2616 - HTTP/1.1.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.HaveResponse Property

public bool HaveResponse { get; }

Summary

Gets a Boolean value indicating whether a response has been received for the current instance.

Property Value

true if a response has been received; otherwise false .

Description

This property is read-only.

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Headers Property

public override WebHeaderCollection Headers { get; set; }

Summary

Gets or sets the collection of HTTP header name/value pairs associated with the current instance.

Property Value

A WebHeaderCollection containing the name/value pairs of the headers for the current instance.

Exceptions

Exception TypeCondition
InvalidOperationExceptionA set operation was requested but data has already been written to the request data stream.

Description

The following table lists the HTTP headers that cannot be set using the collection returned by this property.

HeaderSet by
AcceptSystem.Net.HttpWebRequest.Accept .
ConnectionSystem.Net.HttpWebRequest.Connection .

System.Net.HttpWebRequest.KeepAlive.

Content-LengthSystem.Net.HttpWebRequest.ContentLength.
Content-TypeSystem.Net.HttpWebRequest.ContentType.
ExpectSystem.Net.HttpWebRequest.Expect.
DateSet by the system to the current date.
HostSet by the system to the current host information.
RangeSystem.Net.HttpWebRequest.AddRange(System.Int32,System.Int32) .
RefererSystem.Net.HttpWebRequest.Referer.
Transfer-EncodingSystem.Net.HttpWebRequest.TransferEncoding.

System.Net.HttpWebRequest.SendChunked.

User-AgentSystem.Net.HttpWebRequest.UserAgent.
[Note: This property overrides System.Net.WebRequest.Headers.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.IfModifiedSince Property

public DateTime IfModifiedSince { get; set; }

Summary

Gets or sets the value of the HTTP If-Modified-Since header.

Property Value

A DateTime that contains the contents of the HTTP If-Modified-Since header. The default value is the current date and time of the system.

Description

[Note: For additional information see section 14.25 of IETF RFC 2616 - HTTP/1.1.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.KeepAlive Property

public bool KeepAlive { get; set; }

Summary

Gets or sets a Boolean value indicating whether to make a persistent connection to the server hosting the Internet resource requested by the current instance.

Property Value

true indicates that the current request will contain an HTTP Connection header with the value "Keep-alive" ; otherwise, false . The default value is true .

Description

[Note: An application uses System.Net.HttpWebRequest.KeepAlive to indicate a preference for persistent connections. When this property is true , the application makes persistent connections to the servers that support them.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.MaximumAutomaticRedirections Property

public int MaximumAutomaticRedirections { get; set; }

Summary

Gets or sets the maximum number of redirects that the current instance will follow.

Property Value

A Int32 value that indicates the maximum number of redirection responses that the current instance will follow. The default value is implementation-specific.

Exceptions

Exception TypeCondition
ArgumentExceptionThe value specified for a set operation is less than or equal to zero.

Description

[Note: This property sets the maximum number of redirections for the request to follow if the System.Net.HttpWebRequest.AllowAutoRedirect property is true .]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.MediaType Property

public string MediaType { get; set; }

Summary

Gets or sets the media type of the current request.

Property Value

A String that identifies the media type of the current request. The default value is null .

Description

[Note: The value of this property affects the System.Net.HttpWebResponse.CharacterSet property. When this property is set in the current instance, the corresponding media type is chosen from the list of character sets returned in the response HTTP Content-type header. ]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Method Property

public override string Method { get; set; }

Summary

Gets or sets the HTTP protocol request method used by the current instance.

Property Value

A String containing an HTTP method. The default value is "GET".

Exceptions

Exception TypeCondition
ArgumentExceptionnull , System.String.Empty, or an invalid value was specified for a set operation.

Description

If the System.Net.HttpWebRequest.ContentLength property is set to any value other than -1, the System.Net.HttpWebRequest.Method property is required to be set to a protocol method that sends request data.

The System.Net.HttpWebRequest.Method property can be set to any of the following HTTP 1.1 protocol methods:

HTTP MethodDescription
GETRetrieves in entity-body form the information identified by the System.Net.HttpWebRequest.RequestUri property of the current instance.
HEADIdentical to GET except that the message-body is not returned in the response.
POST Requests that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified the Request-URI in the Request-Line.
PUTRequests that the enclosed entity be stored under the supplied Request-URI.
DELETERequests that the origin server delete the resource identified by the Request-URI.
TRACEInvokes a remote, application-layer loopback of the request message.
OPTIONSRequests information about the communication options available on the request/response chain identified by the Request-URI. [Note: This allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.]

[Note: For detailed information regarding these methods, see sections 9.2 to 9.8 of RFC 2616.

This property overrides System.Net.WebRequest.Method .

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Pipelined Property

public bool Pipelined { get; set; }

Summary

Gets or sets a Boolean value indicating whether to pipeline the current request to the Internet resource.

Property Value

true if the current request can be pipelined; otherwise, false . The default is true .

Description

An application uses this property to indicate a preference for pipelined connections. If System.Net.HttpWebRequest.Pipelined is true , an application makes pipelined connections to servers that support them.

[Note: Pipelined connections are made only when the System.Net.HttpWebRequest.KeepAlive property is true .]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.PreAuthenticate Property

public override bool PreAuthenticate { get; set; }

Summary

Gets or sets a Boolean value that indicates whether to send HTTP preauthentication header information with current instance without waiting for an authentication challenge from the requested resource.

Property Value

true to send a HTTP WWW-authenticate header with the current instance without waiting for an authentication challenge from the requested resource; otherwise, false . The default is false .

Description

When System.Net.HttpWebRequest.PreAuthenticate is true and credentials are supplied, the HTTP WWW-authenticate header is sent with the current instance without waiting for an authentication challenge from the requested resource; otherwise the request uses standard authentication procedures.

[Note: Set this property to true to allow clients to improve server efficiency by avoiding extra round trips caused by authentication challenges.

This property overrides System.Net.WebRequest.PreAuthenticate.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ProtocolVersion Property

public Version ProtocolVersion { get; set; }

Summary

Gets or sets the version of the HTTP protocol to use for the current request.

Property Value

A Version that represents the HTTP version to use for the request. The default is System.Net.HttpVersion.Version11.

Exceptions

Exception TypeCondition
ArgumentExceptionThe HTTP version is set to a value other than 1.0 or 1.1.

Description

The HttpWebRequest class supports only versions 1.0 and 1.1 of HTTP. Setting System.Net.HttpWebRequest.ProtocolVersion to a different version causes a ArgumentException exception to be thrown.

[Note: To set the System.Net.HttpWebRequest.ProtocolVersion property of the current instance, specify one of the members of the use the HttpVersion class. ]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Proxy Property

public override IWebProxy Proxy { get; set; }

Summary

Gets or sets network proxy information for the current instance.

Property Value

The WebProxy instance to use as a proxy for the current instance. The default value is set by calling System.Net.GlobalProxySelection.Select .

Exceptions

Exception TypeCondition
ArgumentNullExceptionA set operation was requested and the specified value was null .
InvalidOperationExceptionA set operation was requested but data has already been sent to the request stream.
SecurityExceptionThe caller does not have permission for the requested operation.

Description

The System.Net.HttpWebRequest.Proxy property identifies the WebProxy instance to use to communicate with the destination server.

[Note: To specify that no proxy should be used, set the System.Net.HttpWebRequest.Proxy property to the proxy instance returned by the System.Net.GlobalProxySelection.GetEmptyWebProxy method.

This property overrides System.Net.WebRequest.Proxy.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Referer Property

public string Referer { get; set; }

Summary

Gets or sets the value of the HTTP Referer header.

Property Value

A String containing the value of the HTTP Referer header. The default value is null .

Description

[Note: For additional information see section 14.36 of IETF RFC 2616 - HTTP/1.1.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.RequestUri Property

public override Uri RequestUri { get; }

Summary

Gets the Uri of the resource that receives requests sent by the current instance.

Property Value

The Uri of the resource that receives requests sent by the current instance.

Description

This property is read-only.

This property is the Uri instance passed to the current instance via the System.Net.WebRequest.Create(System.Uri,System.Boolean) method.

[Note: Following a redirection header does not change the System.Net.HttpWebRequest.RequestUri property. The URI of the resource that actually responded to the current instance is contained by System.Net.HttpWebRequest.Address property of the current instance.

This property overrides System.Net.WebRequest.RequestUri.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.SendChunked Property

public bool SendChunked { get; set; }

Summary

Gets or sets a value indicating whether to send data in segments.

Property Value

true to send data in segments; otherwise, false . The default value is false .

Exceptions

Exception TypeCondition
InvalidOperationExceptionA set operation was requested but data has already been written to the request data stream.

Description

When System.Net.HttpWebRequest.SendChunked is true , the request sends data to the destination in segments. The destination server is required to support receiving chunked data.

[Note: Set this property to true only if the server specified by the System.Net.HttpWebRequest.Address property of the current instance accepts chunked data (i.e. is HTTP/1.1 or greater in compliance). If the server does not accept chunked data, buffer all data to be written and send a HTTP Content-Length header with the buffered data.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.ServicePoint Property

public ServicePoint ServicePoint { get; }

Summary

Gets the service point to use for the current instance.

Property Value

A ServicePoint that represents the network connection to the destination. The value of this property can be, but is not required to be, null until the System.Net.HttpWebRequest.GetResponse method is called.

Description

This property is read-only.

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.Timeout Property

public override int Timeout { get; set; }

Summary

Gets or sets the length of time before the request times out.

Property Value

A Int32 indicating the number of milliseconds to wait for a response until the request times out, or System.Threading.Timeout.Infinite to indicate that the request does not time out.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptionA value less than zero and not equal to System.Threading.Timeout.Infinite is specified for a set operation.

Description

System.Net.HttpWebRequest.Timeout is the number of milliseconds that a synchronous request made with the System.Net.HttpWebRequest.GetResponse method waits for a response. If a resource does not respond within the time-out period, the request throws a WebException with the System.Net.WebException.Status property set to System.Net.WebExceptionStatus.Timeout.

[Note: This property overrides System.Net.WebRequest.Timeout.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.TransferEncoding Property

public string TransferEncoding { get; set; }

Summary

Gets or sets the value of the HTTP Transfer-encoding header.

Property Value

A String that contains the value of the HTTP Transfer-encoding header. The default value is null .

Exceptions

Exception TypeCondition
InvalidOperationExceptionSystem.Net.HttpWebRequest.TransferEncoding is set when System.Net.HttpWebRequest.SendChunked is false .
ArgumentExceptionSystem.Net.HttpWebRequest.TransferEncoding is set to the value "Chunked". This value is case insensitive.

Description

This property can be set in the current instance only if the System.Net.HttpWebRequest.SendChunked property in the current instance is true .

[Note: Clearing System.Net.HttpWebRequest.TransferEncoding by setting it to null has no effect on the value of System.Net.HttpWebRequest.SendChunked.

Values assigned to the System.Net.HttpWebRequest.TransferEncoding property replace any existing contents.

For additional information see section 14.41 of IETF RFC 2616 - HTTP/1.1.

]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace

HttpWebRequest.UserAgent Property

public string UserAgent { get; set; }

Summary

Gets or sets the value of the HTTP User-agent header.

Property Value

A String containing the value of the HTTP User-agent header. The default value is null .

Description

[Note: For additional information see section 14.43 of IETF RFC 2616 - HTTP/1.1.]

See Also

System.Net.HttpWebRequest Class, System.Net Namespace