WebRequest.Create Method (Uri)

May 11, 2014

Initializes a new WebRequest instance for the specified URI scheme.

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

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.

ExceptionCondition
NotSupportedException

The request scheme specified in requestUri has not been registered.

ArgumentNullException

requestUri is null.

SecurityException

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

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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft