Class WebRequest
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
Implements
Inherited Members
Namespace: System.Net
Assembly: System.Net.Http.dll
Syntax
public abstract class WebRequest : MarshalByRefObject, IDisposable
Remarks
This is the base class of all Web resource/protocol objects. This class provides common methods, data and proprties for making the top-level request.
Constructors
WebRequest()
Initializes a new instance of the WebRequest class.
Declaration
protected WebRequest()
Properties
ConnectionGroupName
When overridden in a descendant class, gets or sets the name of the connection group for the request.
Declaration
public virtual string ConnectionGroupName { get; set; }
Property Value
Type | Description |
---|---|
string | The name of the connection group for the request. |
Remarks
This property serves as a way of grouping connections.
ContentLength
When overridden in a descendant class, gets or sets the content length of the request data being sent.
Declaration
public virtual long ContentLength { get; set; }
Property Value
Type | Description |
---|---|
long | The number of bytes of request data being sent. |
Remarks
The content length is the length of the message with the verb. It is useful only with verbs that actually support a message, such as POST; it is not used for the GET verb.
ContentType
When overridden in a descendant class, gets or sets the content type of the request data being sent.
Declaration
public virtual string ContentType { get; set; }
Property Value
Type | Description |
---|---|
string | The content type of the request data. |
Remarks
The content length is the length of the message with the verb. It is useful only with verbs that actually support a message, such as POST; it is not used for the GET verb.
DefaultWebProxy
Gets or sets the global HTTP proxy. The DefaultWebProxy property determines the default proxy that all WebRequest instances use if the request supports proxies and no proxy is set explicitly using the Proxy property. Proxies are currently supported by HttpWebRequest.
Declaration
public static IWebProxy DefaultWebProxy { get; set; }
Property Value
Type | Description |
---|---|
IWebProxy |
Headers
When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
Declaration
public virtual WebHeaderCollection Headers { get; set; }
Property Value
Type | Description |
---|---|
WebHeaderCollection | A |
Method
When overridden in a descendant class, gets or sets the protocol method to use in this request.
Declaration
public virtual string Method { get; set; }
Property Value
Type | Description |
---|---|
string | The protocol method to use in this request. |
Remarks
This property gets or sets the verb to this request, such as GET or POST for HTTP.
Proxy
When overridden in a descendant class, gets or sets the network proxy to use to access this Internet resource.
Declaration
public virtual IWebProxy Proxy { get; set; }
Property Value
Type | Description |
---|---|
IWebProxy | The |
RequestUri
When overridden in a descendant class, gets the URI of the Internet resource associated with the request.
Declaration
public virtual Uri RequestUri { get; }
Property Value
Type | Description |
---|---|
Uri | A |
Remarks
This property is read-only, since the Uri can be specified only on creation.
Timeout
Gets or sets the length of time, in milliseconds, before the request times out.
Declaration
public virtual int Timeout { get; set; }
Property Value
Type | Description |
---|---|
int | The length of time, in milliseconds, until the request times out, or the value Timeout.Infinite to indicate that the request does not time out. The default value is defined by the descendant class. |
Methods
Create(string)
Initializes a new
Declaration
public static WebRequest Create(string requestUriString)
Parameters
Type | Name | Description |
---|---|---|
string | requestUriString | The URI that identifies the Internet resource. |
Returns
Type | Description |
---|---|
WebRequest |
Remarks
This is the main creation routine. The specified Uri is looked up in the prefix match table, and the appropriate handler is invoked to create the object.
Create(Uri)
Creates a
Declaration
public static WebRequest Create(Uri requestUri)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | A Uri containing the URI of the requested resource. |
Returns
Type | Description |
---|---|
WebRequest |
Remarks
This is the main creation routine. The specified Uri is looked up in the prefix match table, and the appropriate handler is invoked to create the object.
Dispose()
Declaration
public void Dispose()
Dispose(bool)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing |
Finalize()
Declaration
protected override void Finalize()
GetRequestStream()
When overridden in a descendant class, returns a
Declaration
public virtual Stream GetRequestStream()
Returns
Type | Description |
---|---|
Stream | A |
GetResponse()
When overridden in a descendant class, returns a response to an Internet request.
Declaration
public virtual WebResponse GetResponse()
Returns
Type | Description |
---|---|
WebResponse | A |
Initialize()
Initialize has to be called before the class is used. Normally should be called by the constructor above.
Declaration
public static void Initialize()
RegisterPrefix(string, IWebRequestCreate)
Registers a
Declaration
public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
Parameters
Type | Name | Description |
---|---|---|
string | prefix | The complete URI or URI prefix that the
|
IWebRequestCreate | creator | The create method that the
|
Returns
Type | Description |
---|---|
bool |