In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "how to use the HttpWebRequest class in C#", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use the HttpWebRequest class in C#" this article.
Provides a HTTP-specific implementation of the WebRequest class.
Inherit the hierarchy System.Object → System.MarshalByRefObject → System.Net.WebRequest → System.Net.HttpWebRequest.
Namespace: System.Net; Assembly: System (in System.dll)
C # syntax:
[SerializableAttribute]
Public class HttpWebRequest: WebRequest, ISerializable
The HttpWebRequest type exposes the following members.
1. The constructor name indicates that HttpWebRequest () is out of date. Initializes a new instance of the HttpWebRequest class. HttpWebRequest (SerializationInfo, StreamingContext) is out of date. Initializes a new instance of the HttpWebRequest class from the specified instance of the SerializationInfo and StreamingContext classes. 2. The attribute name indicates that Accept gets or sets the value of the Accept HTTP header. The Address gets the uniform resource identifier (URI) of the Internet resource that actually responded to the request. AllowAutoRedirect gets or sets a value indicating whether the request should follow the redirected response. AllowReadStreamBuffering gets or sets a value indicating whether data received from the Internet resource is buffered. AllowWriteStreamBuffering gets or sets a value indicating whether data sent to the Internet resource is buffered. AuthenticationLevel gets or sets the level of authentication and impersonation used for this request. (inherited from WebRequest. AutomaticDecompression gets or sets the type of decompression used CachePolicy gets or sets the cache policy for this request. (inherited from WebRequest. ClientCertificates gets or sets the collection of security certificates associated with this request Connection gets or sets the value of the Connection HTTP header. ConnectionGroupName gets or sets the name of the requested connection group. (rewrite WebRequest.ConnectionGroupName. ContentLength gets or sets the Content-lengthHTTP header (rewrite WebRequest.ContentLength. ContentType gets or sets the value of the Content-type HTTP header (rewrite WebRequest.ContentType. ContinueDelegate gets or sets the delegate method that is called when a continuous response from HTTP 100 is received from an Internet resource ContinueTimeout gets or sets the timeout (in milliseconds) to wait before receiving 100 consecutive responses from the server. CookieContainer gets or sets the cookie associated with this request. CreatorInstance is out of date. When overridden in a subclass, gets the factory object derived from the IWebRequestCreate class, which is used to create a WebRequest instantiated to generate a request for the specified URI. (inherited from WebRequest. Credentials gets or sets the requested authentication information (rewrite WebRequest.Credentials. Date gets or sets the Date HTTP header value to be used in the HTTP request DefaultCachePolicy gets or sets the default caching policy for this request. DefaultMaximumErrorResponseLength gets or sets the default maximum length of the HTTP error response. DefaultMaximumResponseHeadersLength gets or sets the default value of the MaximumResponseHeadersLength property. Expect gets or sets the value of the Expect HTTP header. HaveResponse gets a value indicating whether a response from the Internet resource has been received. Headers specifies the collection of name / value pairs that make up the HTTP header. (rewrite WebRequest.Headers. Host gets or sets the Host header value to be used in the HTTP request independently of the request URI IfModifiedSince gets or sets the value of the If-Modified-Since HTTP header. ImpersonationLevel gets or sets the impersonation level of the current request. (inherited from WebRequest. KeepAlive gets or sets a value indicating whether a persistent connection is established with the Internet resource MaximumAutomaticRedirections gets or sets the maximum number of redirects that the request will follow. MaximumResponseHeadersLength gets or sets the maximum length allowed for the response title. MediaType gets or sets the media type of the request. Method gets or sets the method of the request. (rewrite WebRequest.Method. Pipelined gets or sets a value indicating whether the request is transferred to the Internet resource through the pipeline PreAuthenticate gets or sets a value indicating whether an authentication header is sent with the request. (rewrite WebRequest.PreAuthenticate. ProtocolVersion gets or sets the HTTP version used for the request Proxy gets or sets the requested proxy information. (rewrite WebRequest.Proxy. ReadWriteTimeout gets or sets the timeout, in milliseconds, when writing or reading a stream Referer gets or sets the value of the Referer HTTP header. RequestUri gets the original uniform resource identifier (URI) of the request. (rewrite WebRequest.RequestUri. SendChunked gets or sets a value indicating whether to send data fragments to the Internet resource ServerCertificateValidationCallback gets or sets the callback function used to validate the server certificate. ServicePoint gets the service point used for the request. SupportsCookieContainer gets a value indicating whether the request supports CookieContainer. Timeout gets or sets the timeout value in milliseconds for the GetResponse and GetRequestStream methods. (rewrite WebRequest.Timeout. TransferEncoding gets or sets the value of the Transfer-encoding HTTP header UnsafeAuthenticatedConnectionSharing gets or sets a value indicating whether connection sharing with high-speed NTLM authentication is allowed. UseDefaultCredentials gets or sets a Boolean value that controls whether default credentials are sent with the request. (rewrite WebRequest.UseDefaultCredentials. UserAgent gets or sets the value of the User-agent HTTP header 3. The method name indicates that Abort cancels the request for Internet resources. (override WebRequest.Abort (). AddRange (Int32) adds a byte range header to the request for a specific range from the beginning or end of the request data. AddRange (Int64) adds a byte range header of a specific range from the beginning or end of the request data to the request. AddRange (Int32, Int32) adds a byte range header of the specified range to the request. AddRange (Int64, Int64) adds a byte range header of the specified range to the request. AddRange (String, Int32) adds a specific range of Range headers calculated from the beginning or end of the request data to the request. AddRange (String, Int64) adds a specific range of Range headers calculated from the beginning or end of the request data to the request. AddRange (String, Int32, Int32) adds a range header of the specified range to the request. AddRange (String, Int64, Int64) adds a range header of the specified range to the request. BeginGetRequestStream begins an asynchronous request for the Stream object used to write data. (rewrite WebRequest.BeginGetRequestStream (AsyncCallback, Object). BeginGetResponse starts an asynchronous request for an Internet resource (rewrite WebRequest.BeginGetResponse (AsyncCallback, Object). CreateObjRef creates an object that contains all the relevant information needed to generate an agent to communicate with the remote object (inherited from MarshalByRefObject. EndGetRequestStream (IAsyncResult) ends an asynchronous request to the Stream object used to write data (override WebRequest.EndGetRequestStream (IAsyncResult). EndGetRequestStream (IAsyncResult,TransportContext) ends an asynchronous request for the Stream object used to write data and outputs the TransportContext associated with the stream. EndGetResponse ends an asynchronous request for an Internet resource. (override WebRequest.EndGetResponse (IAsyncResult). Equals (Object) determines whether the specified object is equal to the current object. (inherited from Object. Finalize allows objects to attempt to free resources and perform other cleanup operations before garbage collection (inherited from Object. GetHashCode as the default hash function (inherited from Object. GetLifetimeService retrieves the current lifetime service object that controls the lifetime policy for this instance (inherited from MarshalByRefObject. ) GetObjectData infrastructure Populate the SerializationInfo with the data needed to serialize the target object. (rewrite WebRequest.GetObjectData (SerializationInfo, StreamingContext). GetRequestStream () gets the Stream object used to write the request data. (override WebRequest.GetRequestStream (). GetRequestStream (TransportContext) gets the Stream object used to write the request data and outputs the TransportContext associated with the stream. When GetRequestStreamAsync is overridden in a subclass, the Stream used to write data is returned to the Internet resource as an asynchronous operation. (inherited from WebRequest. GetResponse returns a response from the Internet resource (override WebRequest.GetResponse (). GetResponseAsync, when overridden in a subclass, returns the response to the Internet request as an asynchronous operation (inherited from WebRequest. ) GetType gets the Type of the current instance. (inherited from Object. InitializeLifetimeService gets the lifetime service object that controls 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. ) 4. Display the interface implementation name to describe the ISerializable.GetObjectData infrastructure. Populate the SerializationInfo with the data needed to serialize the target object. 5. Remarks
The HttpWebRequest class supports the properties and methods defined in WebRequest, as well as additional properties and methods that enable users to interact directly with servers that use HTTP.
Do not use the HttpWebRequest constructor. Initialize a new HttpWebRequest object using the WebRequest.Create method. If the scheme for uniform Resource Identifier (URI) is http:// or https://, Create returns a HttpWebRequest object.
The GetResponse method issues a synchronization request to the resource specified in the RequestUri property and returns the HttpWebResponse that contains the response. You can use the BeginGetResponse and EndGetResponse methods to make asynchronous requests for resources.
When you want to send data to a resource, the GetRequestStream method returns the Stream object used to send the data. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the sent data stream.
For client authentication using HttpWebRequest, the client certificate must be installed in the current user's my Certificate store.
If an error occurs while accessing the resource, the HttpWebRequest class throws a WebException. The WebException.Status property contains a WebExceptionStatus value indicating the source of the error. When WebException.Status is WebExceptionStatus.ProtocolError, the Response property contains the HttpWebResponse received from the resource.
HttpWebRequest exposes the public HTTP header values sent to Internet resources as properties that are set by the method or system; the following table contains the complete list. You can set other headers in the Headers property to name / value pairs. Note that headers may be changed or added during the server cache request.
The following table lists the HTTP headers set by the property or method or by the system.
Header
Setting party
Accept
Set by the Accept property.
Connection
Set by the Connection property and the KeepAlive property.
Content-Length
Set by the ContentLength property.
Content-Type
Set by the ContentType property.
Expect
Set by the Expect property.
Date
Set by the system to the current date.
Mainframe
Set by the system to the current host information.
If-Modified-Since
Set by the IfModifiedSince property.
Range
Set by the AddRange method.
Referer
Set by the Referer property.
Transfer-Encoding
Set by the TransferEncoding property (the SendChunked property must be true).
User-Agent
Set by the UserAgent property.
Description
HttpWebRequest automatic registration. Before using URI that starts with http:// or https://, you do not need to call the RegisterPrefix method to register System.Net.HttpWebRequest.
The local computer or application configuration file may specify the use of the default agent. If the Proxy property is specified, the proxy settings in the Proxy property override the local computer or application configuration file, and the HttpWebRequest instance applies the specified proxy settings. If no proxy is specified in the configuration file and the Proxy property is not specified, the HttpWebRequest class uses the proxy settings inherited from Internet Explorer on the local computer. If there is no proxy setting in Internet Explorer, the request is sent directly to the server.
The HttpWebRequest class parses a proxy ignore list that inherits from Internet Explorer and contains wildcards, unlike Internet Explorer parsing the ignore list directly. For example, the HttpWebRequest class parses the ignore list from Internet Explorer that contains "nt*" into the regular expression "nt.$". This behavior is different from the native behavior of Internet Explorer. So the URL "http://intxxxxx" ignores proxies that use the HttpWebRequest class, but it does not ignore proxies that use Internet Explorer.
Description
Framework caches SSL sessions when they are created and, if possible, attempts to reuse the cached sessions for new requests. When attempting to reuse SSL sessions, the framework uses the first element of ClientCertificates, if any, and attempts to reuse anonymous sessions if ClientCertificates is empty.
Description
For security reasons, Cookie is disabled by default. If you want to use Cookie, use the CookieContainer property to enable Cookie.
Example
The following code example is URI http://www.contoso.com/. Create a HttpWebRequest.
HttpWebRequest myReq = (HttpWebRequest) WebRequest.Create ("http://www.contoso.com/"); above is all the content of this article" how to use the HttpWebRequest class in C# ", thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.