Export (0) Print
Expand All

WebRequest.Create Method (Uri)

Initializes a new WebRequest instance for the specified URI scheme.

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

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

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 Nothing.

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 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.

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

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

Community Additions

ADD
Show:
© 2014 Microsoft