WebProxy 类

定义

包含 WebRequest 类的 HTTP 代理设置。Contains HTTP proxy settings for the WebRequest class.

public ref class WebProxy : System::Runtime::Serialization::ISerializable
[System.Serializable]
public class WebProxy : System.Runtime.Serialization.ISerializable
type WebProxy = class
    interface ISerializable
    interface IWebProxy
Public Class WebProxy
Implements ISerializable
继承
WebProxy
属性
实现

示例

下面的代码示例将 WebProxy 实例分配给 WebRequest 实例。The following code example assigns a WebProxy instance to a WebRequest instance. WebRequest 实例使用代理连接到外部 Internet 资源。The WebRequest instance uses the proxy to connect to external Internet resources. (有关演示如何使用 WPAD 功能的示例,请参阅 IWebProxyScript 类的文档。)(For an example that demonstrates using the WPAD feature, see the documentation for the IWebProxyScript class.)

WebProxy^ proxyObject = gcnew WebProxy( "http://proxyserver:80/",true );
WebRequest^ req = WebRequest::Create( "http://www.contoso.com" );
req->Proxy = proxyObject;
WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;

Dim proxyObject As New WebProxy("http://proxyserver:80/", True)
Dim req As WebRequest = WebRequest.Create("http://www.contoso.com")
req.Proxy = proxyObject

注解

WebProxy 类包含 WebRequest 实例用来确定是否使用 Web 代理发送请求的代理设置。The WebProxy class contains the proxy settings that WebRequest instances use to determine whether a Web proxy is used to send requests. 全局 Web 代理设置可在计算机和应用程序配置文件中指定,应用程序可以使用 WebProxy 类的实例来自定义 Web 代理使用。Global Web proxy settings can be specified in machine and application configuration files, and applications can use instances of the WebProxy class to customize Web proxy use. WebProxy 类是 IWebProxy 接口的基实现。The WebProxy class is the base implementation of the IWebProxy interface.

若要获取 Web 代理类的实例,可以使用以下任一方法:To obtain instances of the Web proxy class, you can use any of the following methods:

每个方法都提供一个可进一步自定义的 WebProxy 实例;它们之间的区别在于实例在返回到应用程序之前如何初始化。These methods each supply a WebProxy instance that you can further customize; the difference between them is how the instance is initialized before it is returned to your application. WebProxy 构造函数返回 WebProxy 类的实例,该实例的 Address 属性设置为 nullThe WebProxy constructor returns an instance of the WebProxy class with the Address property set to null. 当请求使用处于此状态的 WebProxy 实例时,将不使用代理来发送请求。When a request uses a WebProxy instance in this state, no proxy is used to send the request.

GetDefaultProxy 方法返回 WebProxy 类的实例,并将 AddressBypassProxyOnLocalBypassList 属性设置为 Internet Explorer 5.5 和更高版本使用的值。The GetDefaultProxy method returns an instance of the WebProxy class with the Address, BypassProxyOnLocal, and BypassList properties set to the values used by Internet Explorer 5.5 and later.

Select 方法返回 WebProxy 类的实例,并根据 Internet Explorer 和配置文件设置的组合设置其属性。The Select method returns an instance of the WebProxy class with it properties set according to a combination of Internet Explorer and configuration file settings.

WebProxy 类支持自动检测和执行代理配置脚本。The WebProxy class supports automatic detection and execution of proxy configuration scripts. 此功能也称为 Web 代理自动发现 (WPAD)。This feature is also known as Web Proxy Auto-Discovery (WPAD). 使用自动代理配置时,必须找到、下载、编译和运行配置脚本(通常名为 Wpad)。When using automatic proxy configuration, a configuration script, typically named Wpad.dat, must be located, downloaded, compiled, and run. 如果这些操作成功,该脚本将返回可用于请求的代理。If these operations are successful, the script returns the proxies that can be used for a request.

构造函数

WebProxy()

初始化 WebProxy 类的空实例。Initializes an empty instance of the WebProxy class.

WebProxy(SerializationInfo, StreamingContext)

使用以前序列化的内容初始化 WebProxy 类的实例。Initializes an instance of the WebProxy class using previously serialized content.

WebProxy(String)

用指定的 URI 初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI.

WebProxy(String, Boolean)

使用指定的 URI 和回避设置初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI and bypass setting.

WebProxy(String, Boolean, String[])

使用指定的 URI、回避设置和要回避的 URI 列表初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI, bypass setting, and list of URIs to bypass.

WebProxy(String, Boolean, String[], ICredentials)

使用指定的 URI、回避设置、要回避的 URI 列表和凭据初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified URI, bypass setting, list of URIs to bypass, and credentials.

WebProxy(String, Int32)

使用指定的主机和端口号初始化 WebProxy 类的新实例。Initializes a new instance of the WebProxy class with the specified host and port number.

WebProxy(Uri)

从指定的 WebProxy 实例中初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class from the specified Uri instance.

WebProxy(Uri, Boolean)

使用 WebProxy 实例和回避设置初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class with the Uri instance and bypass setting.

WebProxy(Uri, Boolean, String[])

使用指定的 WebProxy 实例、回避设置和要回避的 URI 列表初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class with the specified Uri instance, bypass setting, and list of URIs to bypass.

WebProxy(Uri, Boolean, String[], ICredentials)

使用指定的 WebProxy 实例、回避设置、要回避的 URI 列表和凭据初始化 Uri 类的新实例。Initializes a new instance of the WebProxy class with the specified Uri instance, bypass setting, list of URIs to bypass, and credentials.

属性

Address

获取或设置代理服务器的地址。Gets or sets the address of the proxy server.

BypassArrayList

获取不使用代理服务器的地址列表。Gets a list of addresses that do not use the proxy server.

BypassList

获取或设置一个地址数组,这些地址不使用代理服务器。Gets or sets an array of addresses that do not use the proxy server.

BypassProxyOnLocal

获取或设置一个值,该值指示是否对本地地址不使用代理服务器。Gets or sets a value that indicates whether to bypass the proxy server for local addresses.

Credentials

获取或设置要提交到代理服务器进行身份验证的凭据。Gets or sets the credentials to submit to the proxy server for authentication.

UseDefaultCredentials

获取或设置 Boolean 值,该值控制 DefaultCredentials 是否随请求一起发送。Gets or sets a Boolean value that controls whether the DefaultCredentials are sent with requests.

方法

CreateDefaultProxy()
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetDefaultProxy()

读取 Internet Explorer 非动态代理设置。Reads the Internet Explorer nondynamic proxy settings.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

使用序列化目标对象所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data that is needed to serialize the target object.

GetProxy(Uri)

返回请求的已代理 URI。Returns the proxied URI for a request.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsBypassed(Uri)

指示是否对指定的主机使用代理服务器。Indicates whether to use the proxy server for the specified host.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

创建系统序列化 WebProxy 对象时所使用的序列化数据和上下文。Creates the serialization data and context that are used by the system to serialize a WebProxy object.

适用于