WebClient.GetWebRequest(Uri) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
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.