Mono Class Library: System.Net.WebRequest Overview | Members

System.Net.WebRequest.CreateDefault Method

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]

public static WebRequest CreateDefault (Uri requestUri)

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

TypeReason
!:System.Security.Permissions.WebPermission [Edit] Requires permission to connect to the requested URI. See NetworkAccess.Connect.

Exceptions

TypeReason
ArgumentNullExceptionrequestUri is null. [Edit]
NotSupportedExceptionThe request scheme specified in requestUri is not registered. [Edit]
System.Security.SecurityExceptionThe caller does not have permission to connect to the requested URI or a URI that the request is redirected to. [Edit]

Remarks

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.
[Edit]

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