Constructs a new instance of a class derived from System.Net.WebRequest. The new instance is of the type registered for the scheme of the specified URI.
- requestUri
- A Uri containing the URI of the requested resource.
A new instance of the type derived from System.Net.WebRequest that is registered for the scheme of the specified Uri .
Type Reason !:System.Security.Permissions.WebPermission Requires permission to connect to the requested URI. See NetworkAccess.Connect.
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.
Note: When this method is invoked, only the scheme portion of requestUri is checked against the list of URIs registered for the current instance. Conversely, when WebRequest.Create(Uri, bool) is invoked, the entire URI is checked against the list of registered URIs.
This example demonstrates the use of the WebRequest.Create(Uri, bool) and WebRequest.CreateDefault(Uri) methods.
C# Example
using System; using System.Net; public class ContosoTextRequest : WebRequest, IWebRequestCreate { public new WebRequest Create(Uri uri) { return new ContosoTextRequest(); } } public class CreateDefaultExample { public static void Main() { ContosoTextRequest contoso = new ContosoTextRequest(); Uri contosoUri = new Uri("http://www.contoso.com/text"); WebRequest.RegisterPrefix("http://www.contoso.com/text", contoso); WebRequest httpContoso = WebRequest.CreateDefault(contosoUri); Console.WriteLine("CreateDefault --> {0}", httpContoso); WebRequest textContoso = WebRequest.Create(contosoUri); Console.WriteLine("Create --> {0}", textContoso); } }The output is
CreateDefault --> System.Net.HttpWebRequest
Create --> ContosoTextRequest
Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0