System.Net.WebRequest.Create Method

Initializes a new System.Net.WebRequest instance for the specified URI scheme.

Syntax

public static WebRequest Create (string requestUriString)

Parameters

requestUriString
The URI that identifies the Internet resource.

Returns

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

Exceptions

TypeReason
ArgumentNullException requestUriString is null.
NotSupportedExceptionThe request scheme specified in requestUri is not registered.
UriFormatExceptionThe URI specified in requestUriString is not a valid URI.
System.Security.SecurityExceptionThe caller does not have permission to connect to the requested URI or a URI that the request is redirected to.

Remarks

The WebRequest.Create(Uri) method returns a descendant of the System.Net.WebRequest class determined at run time as the closest registered match for requestUri.

For example, when a URI beginning with http:// or https:// is passed in requestUri, an System.Net.HttpWebRequest is returned by WebRequest.Create(Uri). If a URI beginning with ftp:// is passed instead, the WebRequest.Create(Uri) method will return a System.Net.FileWebRequest instance. If a URI beginning with file:// is passed instead, the WebRequest.Create(Uri) method will return a System.Net.FileWebRequest instance.

The pre-registered reserve types already registered include the following:

  • http://

  • https://

  • ftp://

  • file://

The .NET Framework includes support for the http://, https://, ftp://, and file:// URI schemes. Custom System.Net.WebRequest descendants to handle other requests are registered with the WebRequest.RegisterPrefix(string, IWebRequestCreate) method.

The WebRequest.Create(Uri) method uses the requestUriString parameter to create a Uri instance that it passes to the new System.Net.WebRequest.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Permissions

TypeReason
!:System.Security.Permissions.WebPermissionRequires permission to connect to the requested URI. See NetworkAccess.Connect.

Requirements

Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0