Condividi tramite


WebRequest.Create Method (Uri)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new WebRequest instance for the specified URI scheme.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Shared Function Create ( _
    requestUri As Uri _
) As WebRequest
public static WebRequest Create(
    Uri requestUri
)

Parameters

  • requestUri
    Type: System.Uri
    A Uri containing the URI of the requested resource.

Return Value

Type: System.Net.WebRequest
A WebRequest descendant for the specific URI scheme.

Exceptions

Exception Condition
NotSupportedException

The request scheme specified in requestUri has not been registered.

ArgumentNullException

requestUri is nulla null reference (Nothing in Visual Basic).

SecurityException

The caller does not have permission to connect to the requested URI or a URI that the request is redirected to.

Remarks

The Create(Uri) method returns a descendant of the WebRequest class determined at run time as the closest registered match for requestUri. By default, The Create method returns a derived instance of the HttpWebRequest class.

For example, if you create a WebRequest descendant, Handler1, to handle requests to https://www.contoso.com/text/ and another named Handler2 to handle requests to https://www.contoso.com/code/, you can use Create method to return the WebRequest descendant associated with either specified URI.

The .NET Framework in Silverlight includes support for the http:// and https:// URI schemes. Custom WebRequest descendants to handle other requests are registered with the RegisterPrefix method.

Platform Notes

Silverlight for Windows Phone Silverlight for Windows Phone

If you attempt to access a file from an FTP site, the application throws NullRefrenceException instead of NotSupportedException.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.