public class HttpWebRequest : WebRequest
Object
MarshalByRefObject
WebRequest
HttpWebRequest
System
Networking
Provides an HTTP-specific implementation of the WebRequest class.
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.
]
Header Set by Accept System.Net.HttpWebRequest.Accept Connection System.Net.HttpWebRequest.Connection System.Net.HttpWebRequest.KeepAlive
Content-Length System.Net.HttpWebRequest.ContentLength Content-Type System.Net.HttpWebRequest.ContentType Expect System.Net.HttpWebRequest.Expect Date Set to current date by the system. Host Set to current host by the system. if-Modified-since System.Net.HttpWebRequest.IfModifiedSince Range System.Net.HttpWebRequest.AddRange(System.Int32,System.Int32) Referer System.Net.HttpWebRequest.Referer Transfer-Encoding System.Net.HttpWebRequest.TransferEncoding System.Net.HttpWebRequest.SendChunked
User-Agent System.Net.HttpWebRequest.UserAgent
System.Net Namespace
HttpWebRequest Methods
HttpWebRequest.Abort Method
HttpWebRequest.AddRange(int, int) Method
HttpWebRequest.AddRange(int) Method
HttpWebRequest.AddRange(System.String, int, int) Method
HttpWebRequest.AddRange(System.String, 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
public override void Abort();
Cancels an asynchronous operation.
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public void AddRange(int from, int to);
Adds a HTTP Range header to the current instance for a specified range.
- from
- A Int32 indicating the starting byte position of the entity-body data to be returned.
- to
- A Int32 indicating the last byte.
Exception Type Condition ArgumentOutOfRangeException from < 0. -or-
to < 0.
-or-
from > to .
InvalidOperationException The range header could not be added.
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public void AddRange(int range);
Adds a HTTP Range header to the current instance for a specific range from the beginning or end of the requested data.
- 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.
Exception Type Condition InvalidOperationException The range header could not be added.
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public void AddRange(string rangeSpecifier, int from, int to);
Adds a HTTP Range header to the current instance for a specified range.
- 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.
Exception Type Condition ArgumentNullException rangeSpecifier is null
.ArgumentOutOfRangeException from < 0. -or-
to < 0.
-or-
from > to .
ArgumentException rangeSpecifier is invalid. InvalidOperationException The range header could not be added.
[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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public void AddRange(string rangeSpecifier, int range);
Adds a HTTP Range header to the current request for a specific range from the beginning or end of the requested data.
- 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.
Exception Type Condition ArgumentNullException rangeSpecifier is null
.ArgumentException rangeSpecifier is invalid. InvalidOperationException The range header could not be added.
[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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state);
Begins an asynchronous request for a stream in which to write data to be sent in the current instance.
- 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
.
A IAsyncResult that contains information about the asynchronous operation.
Exception Type Condition InvalidOperationException The stream is being used by a previous call to System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) . -or-
No writeable stream is available.
ProtocolViolationException The 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".
WebException System.Net.HttpWebRequest.Abort was previously called. -or-
An error occurred while processing the request.
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) .
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state);
Begins sending the current HTTP request asynchronously.
- 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
.
A IAsyncResult that contains information about the asynchronous operation.
Exception Type Condition InvalidOperationException System.Net.HttpWebRequest.BeginGetResponse(System.AsyncCallback,System.Object) or System.Net.HttpWebRequest.GetResponse was previously called on this instance. ProtocolViolationException The System.Net.HttpWebRequest.ContentLength property of the current instance has not been set. WebException System.Net.HttpWebRequest.Abort was previously called.
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).
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override Stream EndGetRequestStream(IAsyncResult asyncResult);
Completes an asynchronous request for a stream that was started by the System.Net.HttpWebRequest.BeginGetRequestStream(System.AsyncCallback,System.Object) method.
- asyncResult
- The IAsyncResult object that holds the state information for the asynchronous operation.
A Stream to write request data to.
Exception Type Condition ArgumentNullException asyncResult is null
.ArgumentException asyncResult 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.
WebException System.Net.HttpWebRequest.Abort was previously called. -or-
An error occurred while processing the request.
[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).
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override WebResponse EndGetResponse(IAsyncResult asyncResult);
Returns a WebResponse that contains a response to the specified pending Internet request.
- asyncResult
- The IAsyncResult object that hold the state information for the asynchronous operation.
A WebResponse that contains a response to the Internet request referenced by asyncResult .
Exception Type Condition ArgumentNullException asyncResult is null
.ArgumentException asyncResult 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.
WebException System.Net.HttpWebRequest.Abort was previously called. -or-
An error occurred while processing the request.
[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).
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override int GetHashCode();
Generates a hash code for the current instance.
A Int32 containing the hash code for the current instance.
The algorithm used to generate the hash code is unspecified.[Note: This method overrides System.Object.GetHashCode.]
System.Net.HttpWebRequest Class, System.Net Namespace
public override Stream GetRequestStream();
Returns a Stream for writing data to the Internet resource requested by the current instance.
A Stream for writing data to an Internet resource requested by the current instance.
Exception Type Condition ProtocolViolationException The 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.
InvalidOperationException The System.Net.HttpWebRequest.GetRequestStream method was called more than once. -or-
No writeable stream is available.
WebException System.Net.HttpWebRequest.Abort was previously called. -or-
The timeout period for the request expired.
-or-
An error occurred while processing the request.
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 may cause the application to run out of connections.
This method overrides System.Net.WebRequest.GetRequestStream.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override WebResponse GetResponse();
Returns a response to an Internet request.
A WebResponse containing the response from the Internet resource requested by the current instance.
Exception Type Condition ProtocolViolationException The System.Net.HttpWebRequest.ContentLength property of the current instance is not set. WebException System.Net.HttpWebRequest.Abort was previously called. -or-
The timeout period for the request expired.
-or-
An error occurred while processing the request.
[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 .
]
System.Net.HttpWebRequest Class, System.Net Namespace
public string Accept { get; set; }
Gets or sets a String containing the value of the HTTP Accept header.
A String containing the value of the HTTP Accept header. The default value of this property isnull
.
[Note: For additional information see section 14.1 of IETF RFC 2068 - HTTP/1.1.]
System.Net.HttpWebRequest Class, System.Net Namespace
public Uri Address { get; }
Gets the URI that responds to the current request.
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.
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.]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool AllowAutoRedirect { get; set; }
Gets or sets a Boolean value that indicates whether the current request will follow redirection responses.
true
if the current request will automatically follow redirection responses from the Internet resource; otherwisefalse
. The default value istrue
.
[Note: Set System.Net.HttpWebRequest.AllowAutoRedirect totrue
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool AllowWriteStreamBuffering { get; set; }
Gets or sets a Boolean value that indicates whether to buffer the data sent to the Internet resource requested by the current instance.
true
to enable buffering of the data sent to the Internet resource requested by the current instance;false
to disable buffering. The default istrue
.
[Note: When System.Net.HttpWebRequest.AllowWriteStreamBuffering istrue
, 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.]
System.Net.HttpWebRequest Class, System.Net Namespace
public string Connection { get; set; }
Gets or sets the value of the Connection HTTP header.
A String containing the value of the Connection HTTP header. The default value isnull
.
Exception Type Condition ArgumentException The value of System.Net.HttpWebRequest.Connection is set to "Keep-alive" or "Close". This value is case insensitive.
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 2068 - HTTP/1.1.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override string ConnectionGroupName { get; set; }
Gets or sets the name of the connection group for the current instance.
A String that contains the name of the connection group for the current instance. The default value isnull
.
[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 may result in exceeding System.Net.ServicePoint.ConnectionLimit for that server.
This property overrides System.Net.WebRequest.ConnectionGroupName.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override long ContentLength { get; set; }
Gets or sets the Content-length HTTP header.
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.
Exception Type Condition InvalidOperationException Data has already been written to the request stream. ArgumentOutOfRangeException A value less than zero is specified for a set operation.
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 2068 - HTTP/1.1.
This property overrides System.Net.WebRequest.ContentLength.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public override string ContentType { get; set; }
Gets or sets the value of the Content-type HTTP header of the current instance.
The value of the Content-type HTTP header of the current instance. The default value isnull
.
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 2068 - HTTP/1.1.
This property overrides System.Net.WebRequest.ContentType.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public HttpContinueDelegate ContinueDelegate { get; set; }
Gets or sets the delegate method whose methods are invoked when an HTTP 100-continue response is received by the current instance.
A HttpContinueDelegate that references the methods that are invoked when an HTTP Continue response is received. The default value isnull
.
[Note: This delegate is useful to display the status of responses received by the current instance.]
System.Net.HttpWebRequest Class, System.Net Namespace
public override ICredentials Credentials { get; set; }
Gets or sets the credentials used for authenticating the current request.
A ICredentials object containing the authentication credentials associated with the current instance. The default isnull
.
[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 .
]
System.Net.HttpWebRequest Class, System.Net Namespace
public string Expect { get; set; }
Gets or sets the value of the HTTP Expect header.
A String that contains the contents of the HTTP Expect header. The default value isnull
.
Exception Type Condition ArgumentException The value specified for a set operation is "100-continue". This value is case insensitive.
[Note: By default, System.Net.HttpWebRequest.Expect isnull
. 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 tonull
.For additional information see section 14.20 of IETF RFC 2068 - HTTP/1.1.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool HaveResponse { get; }
Gets a Boolean value indicating whether a response has been received for the current instance.
true
if a response has been received; otherwisefalse
.
This property is read-only.
System.Net.HttpWebRequest Class, System.Net Namespace
public override WebHeaderCollection Headers { get; set; }
Gets or sets the collection of HTTP header name/value pairs associated with the current instance.
A WebHeaderCollection containing the name/value pairs of the headers for the current instance.
Exception Type Condition InvalidOperationException A set operation was requested but data has already been written to the request data stream.
The following table lists the HTTP headers that cannot be set using the collection returned by this property.
[Note: This property overrides System.Net.WebRequest.Headers.]
Header Set by Accept System.Net.HttpWebRequest.Accept . Connection System.Net.HttpWebRequest.Connection . System.Net.HttpWebRequest.KeepAlive.
Content-Length System.Net.HttpWebRequest.ContentLength. Content-Type System.Net.HttpWebRequest.ContentType. Expect System.Net.HttpWebRequest.Expect. Date Set by the system to the current date. Host Set by the system to the current host information. Range System.Net.HttpWebRequest.AddRange(System.Int32,System.Int32) . Referer System.Net.HttpWebRequest.Referer. Transfer-Encoding System.Net.HttpWebRequest.TransferEncoding.
System.Net.HttpWebRequest.SendChunked.
User-Agent System.Net.HttpWebRequest.UserAgent.
System.Net.HttpWebRequest Class, System.Net Namespace
public DateTime IfModifiedSince { get; set; }
Gets or sets the value of the HTTP If-Modified-Since header.
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.
[Note: For additional information see section 14.25 of IETF RFC 2068 - HTTP/1.1.]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool KeepAlive { get; set; }
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.
true
indicates that the current request will contain an HTTP Connection header with the value "Keep-alive" ; otherwise,false
. The default value istrue
.
[Note: An application uses System.Net.HttpWebRequest.KeepAlive to indicate a preference for persistent connections. When this property istrue
, the application makes persistent connections to the servers that support them.]
System.Net.HttpWebRequest Class, System.Net Namespace
public int MaximumAutomaticRedirections { get; set; }
Gets or sets the maximum number of redirects that the current instance will follow.
A Int32 value that indicates the maximum number of redirection responses that the current instance will follow. The default value is implementation-defined.
Exception Type Condition ArgumentException The value specified for a set operation is less than or equal to zero.
[Note: This property sets the maximum number of redirections for the request to follow if the System.Net.HttpWebRequest.AllowAutoRedirect property istrue
.]
System.Net.HttpWebRequest Class, System.Net Namespace
public string MediaType { get; set; }
Gets or sets the media type of the current request.
A String that identifies the media type of the current request. The default value isnull
.
[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. ]
System.Net.HttpWebRequest Class, System.Net Namespace
public override string Method { get; set; }
Gets or sets the HTTP protocol request method used by the current instance.
A String containing an HTTP method. The default value is "GET".
Exception Type Condition ArgumentException null
, System.String.Empty, or an invalid value was specified for a set operation.
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:
[Note: For detailed information regarding these methods, see sections 9.2 to 9.8 of RFC 2616.
HTTP Method Description GET Retrieves in entity-body form the information identified by the System.Net.HttpWebRequest.RequestUri property of the current instance. HEAD Identical 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. PUT Requests that the enclosed entity be stored under the supplied Request-URI. DELETE Requests that the origin server delete the resource identified by the Request-URI. TRACE Invokes a remote, application-layer loopback of the request message. OPTIONS Requests 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.]
This property overrides System.Net.WebRequest.Method .
]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool Pipelined { get; set; }
Gets or sets a Boolean value indicating whether to pipeline the current request to the Internet resource.
true
if the current request can be pipelined; otherwise,false
. The default istrue
.
An application uses this property to indicate a preference for pipelined connections. If System.Net.HttpWebRequest.Pipelined istrue
, 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
.]
System.Net.HttpWebRequest Class, System.Net Namespace
public override bool PreAuthenticate { get; set; }
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.
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 isfalse
.
When System.Net.HttpWebRequest.PreAuthenticate istrue
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public Version ProtocolVersion { get; set; }
Gets or sets the version of the HTTP protocol to use for the current request.
A Version that represents the HTTP version to use for the request. The default is System.Net.HttpVersion.Version11.
Exception Type Condition ArgumentException The HTTP version is set to a value other than 1.0 or 1.1.
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. ]
System.Net.HttpWebRequest Class, System.Net Namespace
public override IWebProxy Proxy { get; set; }
Gets or sets network proxy information for the current instance.
The WebProxy instance to use as a proxy for the current instance. The default value is set by calling System.Net.GlobalProxySelection.Select .
Exception Type Condition ArgumentNullException A set operation was requested and the specified value was null
.InvalidOperationException A set operation was requested but data has already been sent to the request stream. SecurityException The caller does not have permission for the requested operation.
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public string Referer { get; set; }
Gets or sets the value of the HTTP Referer header.
A String containing the value of the HTTP Referer header. The default value isnull
.
[Note: For additional information see section 14.36 of IETF RFC 2068 - HTTP/1.1.]
System.Net.HttpWebRequest Class, System.Net Namespace
public override Uri RequestUri { get; }
Gets the Uri of the resource that receives requests sent by the current instance.
The Uri of the resource that receives requests sent by the current instance.
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.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public bool SendChunked { get; set; }
Gets or sets a value indicating whether to send data in segments.
true
to send data in segments; otherwise,false
. The default value isfalse
.
Exception Type Condition InvalidOperationException A set operation was requested but data has already been written to the request data stream.
When System.Net.HttpWebRequest.SendChunked istrue
, 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.]
System.Net.HttpWebRequest Class, System.Net Namespace
public ServicePoint ServicePoint { get; }
Gets the service point to use for the current instance.
A ServicePoint that represents the network connection to the destination. The value of this property isnull
until the System.Net.HttpWebRequest.GetResponse method is called.
This property is read-only.
System.Net.HttpWebRequest Class, System.Net Namespace
public override int Timeout { get; set; }
Gets or sets the length of time before the request times out.
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.
Exception Type Condition ArgumentOutOfRangeException A value less than zero and not equal to System.Threading.Timeout.Infinite is specified for a set operation.
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.]
System.Net.HttpWebRequest Class, System.Net Namespace
public string TransferEncoding { get; set; }
Gets or sets the value of the HTTP Transfer-encoding header.
A String that contains the value of the HTTP Transfer-encoding header. The default value isnull
.
Exception Type Condition InvalidOperationException System.Net.HttpWebRequest.TransferEncoding is set when System.Net.HttpWebRequest.SendChunked is false
.ArgumentException System.Net.HttpWebRequest.TransferEncoding is set to the value "Chunked". This value is case insensitive.
This property can be set in the current instance only if the System.Net.HttpWebRequest.SendChunked property in the current instance istrue
.[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 2068 - HTTP/1.1.
]
System.Net.HttpWebRequest Class, System.Net Namespace
public string UserAgent { get; set; }
Gets or sets the value of the HTTP User-agent header.
A String containing the value of the HTTP User-agent header. The default value isnull
.
[Note: For additional information see section 14.43 of IETF RFC 2068 - HTTP/1.1.]
System.Net.HttpWebRequest Class, System.Net Namespace