Class WebRequest
Makes a request to a Uniform Resource Identifier (URI). This is an abstract class.
public abstract class WebRequest : MarshalByRefObject, IDisposable
- Inheritance
-
WebRequest
- Implements
- Derived
- Inherited Members
- Extension Methods
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.
protected WebRequest()
Properties
ConnectionGroupName
When overridden in a descendant class, gets or sets the name of the connection group for the request.
public virtual string ConnectionGroupName { get; set; }
Property Value
- 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.
public virtual long ContentLength { get; set; }
Property Value
- 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.
public virtual string ContentType { get; set; }
Property Value
- 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.
public static IWebProxy DefaultWebProxy { get; set; }
Property Value
Headers
When overridden in a descendant class, gets or sets the collection of header name/value pairs associated with the request.
public virtual WebHeaderCollection Headers { get; set; }
Property Value
- WebHeaderCollection
A
WebHeaderCollection containing the header name/value pairs associated with this request.
Method
When overridden in a descendant class, gets or sets the protocol method to use in this request.
public virtual string Method { get; set; }
Property Value
- 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.
public virtual IWebProxy Proxy { get; set; }
Property Value
- IWebProxy
The
IWebProxy to use to access the Internet resource.
RequestUri
When overridden in a descendant class, gets the URI of the Internet resource associated with the request.
public virtual Uri RequestUri { get; }
Property Value
- Uri
A
Uri representing the resource associated with the request.
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.
public virtual int Timeout { get; set; }
Property Value
- 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
public static WebRequest Create(string requestUriString)
Parameters
requestUriString
stringThe URI that identifies the Internet resource.
Returns
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
public static WebRequest Create(Uri requestUri)
Parameters
Returns
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()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
Finalize()
protected override void Finalize()
GetRequestStream()
When overridden in a descendant class, returns a
public virtual Stream GetRequestStream()
Returns
- Stream
A
Stream for writing data to the Internet resource.
GetResponse()
When overridden in a descendant class, returns a response to an Internet request.
public virtual WebResponse GetResponse()
Returns
- WebResponse
A
WebResponse containing the response to the Internet request.
Initialize()
Initialize has to be called before the class is used. Normally should be called by the constructor above.
public static void Initialize()
RegisterPrefix(string, IWebRequestCreate)
Registers a
public static bool RegisterPrefix(string prefix, IWebRequestCreate creator)
Parameters
prefix
stringThe complete URI or URI prefix that the
WebRequest descendant services.creator
IWebRequestCreateThe create method that the
WebRequest calls to create theWebRequest descendant.
Returns
- bool
true .