WebRequest.RegisterPrefix(String, IWebRequestCreate) 方法

定义

为指定的 URI 注册 WebRequest 子代。

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 前缀。

creator
IWebRequestCreate

创建方法,WebRequest 调用它以创建 WebRequest 子代。

返回

如果注册成功,则为 true;否则为 false

例外

prefixnull

- 或 -

creatornull

注解

方法 RegisterPrefixWebRequest 后代注册到服务请求。 WebRequest 后代通常注册以处理特定协议(如 HTTP 或 FTP),但可以注册以处理对服务器上特定服务器或路径的请求。

已注册的预注册保留类型包括:

  • http://

  • https://

  • ftp://

  • file://

有关详细信息,请参阅 Create(String)Create(Uri) 方法。

不允许重复前缀。 RegisterPrefixfalse如果尝试注册重复前缀,则返回 。

备注

默认情况下,类 HttpWebRequest 注册到 HTTP 和 HTTPS 方案的服务请求。 尝试为这些方案注册不同的 WebRequest 后代将失败。

适用于