संपादित करें

इसके माध्यम से साझा किया गया


WebClient.GetWebRequest(Uri) Method

Definition

Returns a WebRequest object for the specified resource.

protected:
 virtual System::Net::WebRequest ^ GetWebRequest(Uri ^ address);
protected virtual System.Net.WebRequest GetWebRequest (Uri address);
abstract member GetWebRequest : Uri -> System.Net.WebRequest
override this.GetWebRequest : Uri -> System.Net.WebRequest
Protected Overridable Function GetWebRequest (address As Uri) As WebRequest

Parameters

address
Uri

A Uri that identifies the resource to request.

Returns

A new WebRequest object for the specified resource.

Examples

The following code example shows an implementation of this method that can be customized by a class derived from WebClient.

virtual WebRequest^ GetWebRequest ( Uri^ address ) override
{
   WebRequest^ request = dynamic_cast<WebRequest^>(WebClient::GetWebRequest( address ));

   // Perform any customizations on the request.
   // This version of WebClient always preauthenticates.
   request->PreAuthenticate = true;
   return request;
}
protected override WebRequest GetWebRequest (Uri address)
{
    WebRequest request = (WebRequest) base.GetWebRequest (address);

    // Perform any customizations on the request.
    // This version of WebClient always preauthenticates.
    request.PreAuthenticate = true;
    return request;
}

Remarks

Caution

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

This method copies the existing Headers, Credentials, and method to the newly created WebRequest object.

This method can be called only by classes that inherit from WebClient. It is provided to give inheritors access to the underlying WebRequest object. Derived classes should call the base class implementation of GetWebRequest to ensure the method works as expected.

Applies to