WebRequest.RegisterPrefix Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Registers a WebRequest descendant for the specified URI.
Assembly: System.Net (in System.Net.dll)
'Declaration Public Shared Function RegisterPrefix ( _ prefix As String, _ creator As IWebRequestCreate _ ) As Boolean
Parameters
- prefix
- Type: System.String
The complete URI or URI prefix that the WebRequest descendant services.
- creator
- Type: System.Net.IWebRequestCreate
The create method that the WebRequest calls to create the WebRequest descendant.
| Exception | Condition |
|---|---|
| ArgumentNullException | prefix is Nothing -or- creator is Nothing. |
| NotSupportedException | prefix is unknown or not supported. |
The RegisterPrefix method registers WebRequest descendants to service requests. WebRequest descendants are typically registered to handle a specific protocol, such HTTP or HTTPS, but can be registered to handle a request to a specific server or path on a server.
Duplicate prefixes are not allowed. RegisterPrefix returns false if an attempt is made to register a duplicate prefix.
Note: |
|---|
The HttpWebRequest class is registered to service requests for HTTP and HTTPS schemes by default. Attempts to register a different WebRequest descendant for these schemes will fail. |
The RegisterPrefix method allows an application to configure which derived WebRequest type will be instantiated when making a request to a specific URI. WebRequest creators are typically registered to handle a specific protocol, such HTTP or HTTPS, but can be registered to handle a request to a specific server or path on a server. This method is useful when more than one derived WebRequest type can process requests for the same protocol. Windows Phone supports multiple HTTP handlers each having different capabilities. The RegisterPrefix method is a convenient way to indicate which handler to use depending on the target of the request and the capabilities it requires. For example, a web service that uses Representational State Transfer (REST) might require the WebRequestCreator.ClientHttp handler.
Note: