WebRequest.Create Method (Uri)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Initializes a new WebRequest instance for the specified URI scheme.

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

Syntax

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

Parameters

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 nullNothingnullptra 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 http://www.contoso.com/text/ and another named Handler2 to handle requests to http://www.contoso.com/code/, you can use Create method to return the WebRequest descendant associated with either specified URI.

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

Version Notes

Windows Phone

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

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

See Also

Reference

WebRequest Class

Create Overload

System.Net Namespace

CreateHttp

RegisterPrefix

WebRequestCreator