ServicePointManager.FindServicePoint 方法

定義

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件來管理此請求的通訊。

多載

名稱 Description
FindServicePoint(Uri, IWebProxy)
已淘汰.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定 Uri 物件的通訊。

FindServicePoint(Uri)
已淘汰.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定 Uri 物件的通訊。

FindServicePoint(String, IWebProxy)
已淘汰.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定統一資源識別碼(URI)的通訊。

FindServicePoint(Uri, IWebProxy)

來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs

警告

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定 Uri 物件的通訊。

public:
 static System::Net::ServicePoint ^ FindServicePoint(Uri ^ address, System::Net::IWebProxy ^ proxy);
public static System.Net.ServicePoint FindServicePoint(Uri address, System.Net.IWebProxy? proxy);
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(Uri address, System.Net.IWebProxy? proxy);
public static System.Net.ServicePoint FindServicePoint(Uri address, System.Net.IWebProxy proxy);
static member FindServicePoint : Uri * System.Net.IWebProxy -> System.Net.ServicePoint
[<System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member FindServicePoint : Uri * System.Net.IWebProxy -> System.Net.ServicePoint
Public Shared Function FindServicePoint (address As Uri, proxy As IWebProxy) As ServicePoint

參數

address
Uri

一個 Uri 包含網際網路資源地址的物件,供聯絡。

proxy
IWebProxy

這個請求的代理資料。

傳回

ServicePoint管理請求通訊的物件。

屬性

例外狀況

addressnull

已達到定義的ServicePoint物件數量MaxServicePoints上限。

備註

該方法會 FindServicePoint 回傳 ServicePoint 與指定網際網路主機名稱相關的物件。 如果該主機沒有 ServicePoint 物件,該物件就會 ServicePointManager 產生一個。

另請參閱

適用於

FindServicePoint(Uri)

來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs

警告

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定 Uri 物件的通訊。

public:
 static System::Net::ServicePoint ^ FindServicePoint(Uri ^ address);
public static System.Net.ServicePoint FindServicePoint(Uri address);
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(Uri address);
static member FindServicePoint : Uri -> System.Net.ServicePoint
[<System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member FindServicePoint : Uri -> System.Net.ServicePoint
Public Shared Function FindServicePoint (address As Uri) As ServicePoint

參數

address
Uri

Uri網路資源的目標是要聯絡。

傳回

ServicePoint管理請求通訊的物件。

屬性

例外狀況

addressnull

已達到定義的ServicePoint物件數量MaxServicePoints上限。

備註

該方法會 FindServicePoint 回傳 ServicePoint 與指定網際網路主機名稱相關的物件。 如果該主機沒有 ServicePoint 物件,該物件就會 ServicePointManager 產生一個。

另請參閱

適用於

FindServicePoint(String, IWebProxy)

來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs
來源:
ServicePointManager.cs

警告

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.

尋找現有 ServicePoint 物件或建立新 ServicePoint 物件以管理與指定統一資源識別碼(URI)的通訊。

public:
 static System::Net::ServicePoint ^ FindServicePoint(System::String ^ uriString, System::Net::IWebProxy ^ proxy);
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy);
[System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy);
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy proxy);
static member FindServicePoint : string * System.Net.IWebProxy -> System.Net.ServicePoint
[<System.Obsolete("WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete. Use HttpClient instead.", DiagnosticId="SYSLIB0014", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
static member FindServicePoint : string * System.Net.IWebProxy -> System.Net.ServicePoint
Public Shared Function FindServicePoint (uriString As String, proxy As IWebProxy) As ServicePoint

參數

uriString
String

要聯絡的網際網路資源的URI。

proxy
IWebProxy

這個請求的代理資料。

傳回

ServicePoint管理請求通訊的物件。

屬性

例外狀況

該 URI 在 中 uriString 指定的是無效的。

已達到定義的ServicePoint物件數量MaxServicePoints上限。

範例

以下程式碼範例示範呼叫此方法以存取物件 ServicePoint

public static void Main(string[] args)
{
    int port = 80;

    // Define a regular expression to parse the user's input.
    // This is a security check. It allows only
    // alphanumeric input strings between 2 to 40 characters long.
    Regex rex = new Regex(@"^[a-zA-Z]\w{1,39}$");

    if (args.Length < 1)
    {
        showUsage();
        return;
    }
    string proxy = args[0];

    if (!(rex.Match(proxy)).Success)
    {
        Console.WriteLine("Input string format not allowed.");
        return;
    }
    string proxyAdd = "http://" + proxy + ":" + port;

    // Create a proxy object.
    WebProxy DefaultProxy = new WebProxy(proxyAdd, true);

    // Set the proxy that all HttpWebRequest instances use.
    WebRequest.DefaultWebProxy = DefaultProxy;

    // Get the base interface for proxy access for the
    // WebRequest-based classes.
    IWebProxy Iproxy = WebRequest.DefaultWebProxy;

    // Set the maximum number of ServicePoint instances to
    // maintain. If a ServicePoint instance for that host already
    // exists when your application requests a connection to
    // an Internet resource, the ServicePointManager object
    // returns this existing ServicePoint instance. If none exists
    // for that host, it creates a new ServicePoint instance.
    ServicePointManager.MaxServicePoints = 4;

    // Set the maximum idle time of a ServicePoint instance to 10 seconds.
    // After the idle time expires, the ServicePoint object is eligible for
    // garbage collection and cannot be used by the ServicePointManager object.
    ServicePointManager.MaxServicePointIdleTime = 10000;

    ServicePointManager.UseNagleAlgorithm = true;
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.CheckCertificateRevocationList = true;
    ServicePointManager.DefaultConnectionLimit = ServicePointManager.DefaultPersistentConnectionLimit;
    // Create the Uri object for the resource you want to access.
    Uri MS = new Uri("http://msdn.microsoft.com/");

    // Use the FindServicePoint method to find an existing
    // ServicePoint object or to create a new one.
    ServicePoint servicePoint = ServicePointManager.FindServicePoint(MS, Iproxy);

    ShowProperties(servicePoint);

    int hashCode = servicePoint.GetHashCode();

    Console.WriteLine("Service point hashcode: " + hashCode);

    // Make a request with the same scheme identifier and host fragment
    // used to create the previous ServicePoint object.
    makeWebRequest(hashCode, "http://msdn.microsoft.com/library/");
}
' This is the program entry point. It allows the user to enter 
' a server name that is used to locate its current homepage.
Public Shared Sub Main(ByVal args() As String)
    Dim proxy As String = Nothing
    Dim port As Integer = 80

    ' Define a regular expression to parse the user's input.
    ' This is a security check. It allows only
    ' alphanumeric input strings between 2 to 40 characters long.
    Dim rex As New Regex("^[a-zA-Z]\w{1,39}$")

    If args.Length = 0 Then
        ' Show how to use this program.
        showUsage()
        Return
    End If

    proxy = args(0)
    If (Not (rex.Match(proxy)).Success) Then
        Console.WriteLine("Input string format not allowed.")
        Return
    End If

    ' Create a proxy object.  
    Dim proxyAdd As String
    proxyAdd = "http://" + proxy + ":" + port.ToString()


    Dim DefaultProxy As New WebProxy(proxyAdd, True)

    ' Set the proxy that all HttpWebRequest instances use.
    WebRequest.DefaultWebProxy = DefaultProxy


    ' Get the base interface for proxy access for the 
    ' WebRequest-based classes.
    Dim Iproxy As IWebProxy = WebRequest.DefaultWebProxy

    ' Set the maximum number of ServicePoint instances to maintain.
    ' Note that, if a ServicePoint instance for that host already 
    ' exists when your application requests a connection to
    ' an Internet resource, the ServicePointManager object
    ' returns this existing ServicePoint. If none exists 
    ' for that host, it creates a new ServicePoint instance.
    ServicePointManager.MaxServicePoints = 4

    ' Set the maximum idle time of a ServicePoint instance to 10 seconds.
    ' After the idle time expires, the ServicePoint object is eligible for
    ' garbage collection and cannot be used by the ServicePointManager.
    ServicePointManager.MaxServicePointIdleTime = 10000


    ServicePointManager.UseNagleAlgorithm = True
    ServicePointManager.Expect100Continue = True
    ServicePointManager.CheckCertificateRevocationList = True
    ServicePointManager.DefaultConnectionLimit = _
        ServicePointManager.DefaultPersistentConnectionLimit
    ' Create the Uri object for the resource you want to access.
    Dim MS As New Uri("http://msdn.microsoft.com/")

    ' Use the FindServicePoint method to find an existing 
    ' ServicePoint object or to create a new one.   
    Dim servicePoint As ServicePoint = ServicePointManager.FindServicePoint(MS, Iproxy)
    ShowProperties(servicePoint)
    Dim hashCode As Integer = servicePoint.GetHashCode()
    Console.WriteLine(("Service point hashcode: " + hashCode.ToString()))

    ' Make a request with the same scheme identifier and host fragment
    ' used to create the previous ServicePoint object.
    makeWebRequest(hashCode, "http://msdn.microsoft.com/library/")

End Sub

備註

該方法會 FindServicePoint 回傳 ServicePoint 與指定網際網路主機名稱相關的物件。 如果該主機沒有 ServicePoint 物件,該物件就會 ServicePointManager 產生一個。

另請參閱

適用於