【发布时间】:2009-12-18 16:38:38
【问题描述】:
有人能解释一下 ServicePointManager.FindServicePoint 的用途吗?我一直在编写一些代码来使用 C# 中的代理,并且已经看到它可能在这方面有用的指标,但看不出为什么或如何。应该如何(或何时)使用这个类(ServicePointManager)或方法(ServicePointManager.FindServicePoint)?
谢谢。
【问题讨论】:
有人能解释一下 ServicePointManager.FindServicePoint 的用途吗?我一直在编写一些代码来使用 C# 中的代理,并且已经看到它可能在这方面有用的指标,但看不出为什么或如何。应该如何(或何时)使用这个类(ServicePointManager)或方法(ServicePointManager.FindServicePoint)?
谢谢。
【问题讨论】:
ServicePointManager.FindServicePoint(...) 方法将帮助您获取您在配置文件中指定的ServicePoint 对象。
假设这是你的配置文件:
<configuration>
<system.net>
<connectionManagement>
<add address="http://www.contoso.com" maxconnection="2" />
<add address="192.168.1.2" maxconnection="4" />
<add address="*" maxconnection="1" />
</connectionManagement>
</system.net>
</configuration>
此代码将检索“http://www.microsoft.com”ServicePoint:
ServicePoint sp1 = ServicePointManager.FindServicePoint(new Uri("http://www.microsoft.com"));
您可以阅读所有相关信息here。
【讨论】: