WebRequest.RegisterPrefix(String, IWebRequestCreate) 方法

定义

为指定的 URI 注册 WebRequest 子代。Registers a WebRequest descendant for the specified URI.

public:
 static bool RegisterPrefix(System::String ^ prefix, System::Net::IWebRequestCreate ^ creator);
public static bool RegisterPrefix (string prefix, System.Net.IWebRequestCreate creator);
static member RegisterPrefix : string * System.Net.IWebRequestCreate -> bool
Public Shared Function RegisterPrefix (prefix As String, creator As IWebRequestCreate) As Boolean

参数

prefix
String

WebRequest 子代为其提供服务的完整 URI 或 URI 前缀。The complete URI or URI prefix that the WebRequest descendant services.

creator
IWebRequestCreate

创建方法,WebRequest 调用它以创建 WebRequest 子代。The create method that the WebRequest calls to create the WebRequest descendant.

返回

如果注册成功,则为 true;否则为 falsetrue if registration is successful; otherwise, false.

异常

prefixnullprefix is null

-or- creatornullcreator is null.

注解

方法将子代WebRequest注册到服务请求。 RegisterPrefixThe RegisterPrefix method registers WebRequest descendants to service requests. WebRequest通常会将子代注册为处理特定协议(如 HTTP 或 FTP),但可以注册子代来处理对服务器上特定服务器或路径的请求。WebRequest descendants are typically registered to handle a specific protocol, such HTTP or FTP, but can be registered to handle a request to a specific server or path on a server.

已注册的预注册的预留类型包括:The pre-registered reserve types already registered include the following:

  • http://

  • https://

  • ftp://

  • file://

有关详细信息,请参阅Create(String)Create(Uri)方法。For more information, see the Create(String) and Create(Uri) methods.

不允许使用重复的前缀。Duplicate prefixes are not allowed. RegisterPrefix如果false尝试注册重复的前缀,则返回。RegisterPrefix returns false if an attempt is made to register a duplicate prefix.

备注

默认情况下,类将注册到HTTP和HTTPS方案的服务请求。HttpWebRequestThe HttpWebRequest class is registered to service requests for HTTP and HTTPS schemes by default. 尝试为这些方案注册WebRequest不同的后代会失败。Attempts to register a different WebRequest descendant for these schemes will fail.

适用于