Initializes a new System.Net.WebRequest instance for the specified URI scheme.
- requestUri
- A Uri containing the URI of the requested resource.
A System.Net.WebRequest descendant for the specified URI scheme.
Type Reason ArgumentNullException requestUri is null. NotSupportedException The request scheme specified in requestUri is not registered. System.Security.SecurityException The caller does not have permission to connect to the requested URI or a URI that the request is redirected to.
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, if you create a System.Net.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 WebRequest.Create(Uri) method to return the WebRequest descendant associated with either specified URI.
To return a descendant of the System.Net.WebRequest class based on only the scheme portion of a URI, use the WebRequest.CreateDefault(Uri) method.
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.
This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].
Type | Reason |
---|---|
!:System.Security.Permissions.WebPermission | Requires permission to connect to the requested URI. See NetworkAccess.Connect. |