Provides an HTTP-specific implementation of the WebRequest class.
public ref class HttpWebRequest : System::Net::WebRequest
public ref class HttpWebRequest : System::Net::WebRequest, System::Runtime::Serialization::ISerializable
public class HttpWebRequest : System.Net.WebRequest
public class HttpWebRequest : System.Net.WebRequest, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HttpWebRequest : System.Net.WebRequest, System.Runtime.Serialization.ISerializable
type HttpWebRequest = class
inherit WebRequest
type HttpWebRequest = class
inherit WebRequest
interface ISerializable
[<System.Serializable>]
type HttpWebRequest = class
inherit WebRequest
interface ISerializable
Public Class HttpWebRequest
Inherits WebRequest
Public Class HttpWebRequest
Inherits WebRequest
Implements ISerializable
The following code example creates an HttpWebRequest for the URI http://www.contoso.com/
.
HttpWebRequest myReq =
(HttpWebRequest)WebRequest.Create("http://www.contoso.com/");
Dim myReq As HttpWebRequest = _
WebRequest.Create("http://www.contoso.com/")
Caution
WebRequest
, HttpWebRequest
, ServicePoint
, and WebClient
are obsolete, and you shouldn't use them for new development. Use HttpClient instead.
The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.
Do not use the HttpWebRequest constructor. Use the WebRequest.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http://
or https://
, Create returns an HttpWebRequest object.
The GetResponse method makes a synchronous request to the resource specified in the RequestUri property and returns an HttpWebResponse that contains the response object. The response data can be received by using the stream returned by GetResponseStream. If the response object or the response stream is closed, remaining data will be forfeited. The remaining data will be drained and the socket will be re-used for subsequent requests when closing the response object or stream if the following conditions hold: it's a keep-alive or pipelined request, only a small amount of data needs to be received, or the remaining data is received in a small time interval. If none of the mentioned conditions hold or the drain time is exceeded, the socket will be closed. For keep-alive or pipelined connections, we strongly recommend that the application reads the streams until EOF. This ensures that the socket will be re-used for subsequent requests resulting in better performance and less resources used.
When you want to send data to the resource, the GetRequestStream method returns a Stream object to use to send data. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the send data stream.
For client authentication with HttpWebRequest, the client certificate must be installed in the My certificate store of the current user.
The HttpWebRequest class throws a WebException when errors occur while accessing a resource. The WebException.Status property contains a WebExceptionStatus value that indicates the source of the error. When WebException.Status is WebExceptionStatus.ProtocolError, the Response property contains the HttpWebResponse received from the resource.
HttpWebRequest exposes common HTTP header values sent to the Internet resource as properties, set by methods, or set by the system; the following table contains a complete list. You can set other headers in the Headers property as name/value pairs. Note that servers and caches may change or add headers during the request.
The following table lists the HTTP headers that are set either by properties or methods or the system.
The local computer or application config file may specify that a default proxy be used. If the Proxy property is specified, then the proxy settings from the Proxy property override the local computer or application config file and the HttpWebRequest instance will use the proxy settings specified. If no proxy is specified in a config file and the Proxy property is unspecified, the HttpWebRequest class uses the proxy settings inherited from Internet options on the local computer. If there are no proxy settings in Internet options, the request is sent directly to the server.
Note
The Framework caches SSL sessions as they are created and attempts to reuse a cached session for a new request, if possible. When attempting to reuse an SSL session, the Framework uses the first element of ClientCertificates (if there is one), or tries to reuse an anonymous sessions if ClientCertificates is empty.
Note
For security reasons, cookies are disabled by default. If you want to use cookies, use the CookieContainer property to enable cookies.
For apps that use TLS/SSL through APIs such as HttpClient, HttpWebRequest, FTPClient, SmtpClient, and SsStream, .NET blocks insecure cipher and hashing algorithms for connections by default. You might need to opt out of this behavior to maintain interoperability with existing SSL3 services OR TLS w/ RC4 services. Cannot connect to a server by using the ServicePointManager or SslStream APIs after upgrade to the .NET Framework 4.6 explains how to modify your code to disable this behavior, if necessary.
Constructors Properties AcceptGets or sets the value of the Accept
HTTP header.
Gets the Uniform Resource Identifier (URI) of the Internet resource that actually responds to the request.
AllowAutoRedirectGets or sets a value that indicates whether the request should follow redirection responses.
AllowReadStreamBufferingGets or sets a value that indicates whether to buffer the received from the Internet resource.
AllowWriteStreamBufferingGets or sets a value that indicates whether to buffer the data sent to the Internet resource.
AuthenticationLevelGets or sets values indicating the level of authentication and impersonation used for this request.
(Inherited from WebRequest) AutomaticDecompressionGets or sets the type of decompression that is used.
CachePolicyGets or sets the cache policy for this request.
(Inherited from WebRequest) ClientCertificatesGets or sets the collection of security certificates that are associated with this request.
ConnectionGets or sets the value of the Connection
HTTP header.
Gets or sets the name of the connection group for the request.
ContentLengthGets or sets the Content-length
HTTP header.
Gets or sets the value of the Content-type
HTTP header.
Gets or sets the delegate method called when an HTTP 100-continue response is received from the Internet resource.
ContinueTimeoutGets or sets a timeout, in milliseconds, to wait until the 100-Continue is received from the server.
CookieContainerGets or sets the cookies associated with the request.
CreatorInstanceObsolete.
When overridden in a descendant class, gets the factory object derived from the IWebRequestCreate class used to create the WebRequest instantiated for making the request to the specified URI.
(Inherited from WebRequest) CredentialsGets or sets authentication information for the request.
DateGets or sets the Date
HTTP header value to use in an HTTP request.
Gets or sets the default cache policy for this request.
DefaultMaximumErrorResponseLengthGets or sets the default maximum length of an HTTP error response.
DefaultMaximumResponseHeadersLengthGets or sets the default for the MaximumResponseHeadersLength property.
ExpectGets or sets the value of the Expect
HTTP header.
Gets a value that indicates whether a response has been received from an Internet resource.
HeadersSpecifies a collection of the name/value pairs that make up the HTTP headers.
HostGets or sets the Host header value to use in an HTTP request independent from the request URI.
IfModifiedSinceGets or sets the value of the If-Modified-Since
HTTP header.
Gets or sets the impersonation level for the current request.
(Inherited from WebRequest) KeepAliveGets or sets a value that indicates whether to make a persistent connection to the Internet resource.
MaximumAutomaticRedirectionsGets or sets the maximum number of redirects that the request follows.
MaximumResponseHeadersLengthGets or sets the maximum allowed length of the response headers.
MediaTypeGets or sets the media type of the request.
MethodGets or sets the method for the request.
PipelinedGets or sets a value that indicates whether to pipeline the request to the Internet resource.
PreAuthenticateGets or sets a value that indicates whether to send an Authorization header with the request.
ProtocolVersionGets or sets the version of HTTP to use for the request.
ProxyGets or sets proxy information for the request.
ProxyWhen overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
(Inherited from WebRequest) ReadWriteTimeoutGets or sets a time-out in milliseconds when writing to or reading from a stream.
RefererGets or sets the value of the Referer
HTTP header.
Gets the original Uniform Resource Identifier (URI) of the request.
SendChunkedGets or sets a value that indicates whether to send data in segments to the Internet resource.
ServerCertificateValidationCallbackGets or sets a callback function to validate the server certificate.
ServicePointGets the service point to use for the request.
SupportsCookieContainerGets a value that indicates whether the request provides support for a CookieContainer.
TimeoutGets or sets the time-out value in milliseconds for the GetResponse() and GetRequestStream() methods.
TransferEncodingGets or sets the value of the Transfer-encoding
HTTP header.
Gets or sets a value that indicates whether to allow high-speed NTLM-authenticated connection sharing.
UseDefaultCredentialsGets or sets a Boolean value that controls whether default credentials are sent with requests.
UserAgentGets or sets the value of the User-agent
HTTP header.
Cancels a request to an Internet resource.
AddRange(Int32, Int32)Adds a byte range header to the request for a specified range.
AddRange(Int32)Adds a byte range header to a request for a specific range from the beginning or end of the requested data.
AddRange(Int64, Int64)Adds a byte range header to the request for a specified range.
AddRange(Int64)Adds a byte range header to a request for a specific range from the beginning or end of the requested data.
AddRange(String, Int32, Int32)Adds a range header to a request for a specified range.
AddRange(String, Int32)Adds a Range header to a request for a specific range from the beginning or end of the requested data.
AddRange(String, Int64, Int64)Adds a range header to a request for a specified range.
AddRange(String, Int64)Adds a Range header to a request for a specific range from the beginning or end of the requested data.
BeginGetRequestStream(AsyncCallback, Object)Begins an asynchronous request for a Stream object to use to write data.
BeginGetResponse(AsyncCallback, Object)Begins an asynchronous request to an Internet resource.
CreateObjRef(Type)Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.
(Inherited from MarshalByRefObject) EndGetRequestStream(IAsyncResult, TransportContext)Ends an asynchronous request for a Stream object to use to write data and outputs the TransportContext associated with the stream.
EndGetRequestStream(IAsyncResult)Ends an asynchronous request for a Stream object to use to write data.
EndGetResponse(IAsyncResult)Ends an asynchronous request to an Internet resource.
Equals(Object)Determines whether the specified object is equal to the current object.
(Inherited from Object) GetHashCode()Returns a hash value for a WebRequest instance.
GetHashCode()Serves as the default hash function.
(Inherited from Object) GetLifetimeService()Obsolete.
Retrieves the current lifetime service object that controls the lifetime policy for this instance.
(Inherited from MarshalByRefObject) GetObjectData(SerializationInfo, StreamingContext)Obsolete.
Obsolete.
Obsolete.
Populates a SerializationInfo with the data required to serialize the target object.
GetRequestStream()Gets a Stream object to use to write request data.
GetRequestStream(TransportContext)Gets a Stream object to use to write request data and outputs the TransportContext associated with the stream.
GetRequestStreamAsync()When overridden in a descendant class, returns a Stream for writing data to the Internet resource as an asynchronous operation.
(Inherited from WebRequest) GetResponse()Returns a response from an Internet resource.
GetResponseAsync()When overridden in a descendant class, returns a response to an Internet request as an asynchronous operation.
(Inherited from WebRequest) GetType()Gets the Type of the current instance.
(Inherited from Object) InitializeLifetimeService()Obsolete.
Obtains a lifetime service object to control the lifetime policy for this instance.
(Inherited from MarshalByRefObject) MemberwiseClone()Creates a shallow copy of the current Object.
(Inherited from Object) MemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object.
(Inherited from MarshalByRefObject) ToString()Returns a string that represents the current object.
(Inherited from Object) Explicit Interface Implementations See alsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4