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.
[Edit]
Parameters
- requestUri
- A Uri containing the URI of the requested resource.
[Edit]
Returns
A new instance of the type derived from System.Net.WebRequest that is registered for the scheme of the specified Uri .
[Edit]
Permissions
Exceptions
Remarks
Example
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
Requirements
Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0