Olvasás angol nyelven Szerkesztés

Megosztás a következőn keresztül:


ServicePointManager.FindServicePoint Method

Definition

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communication for this request.

Overloads

FindServicePoint(Uri, IWebProxy)
Obsolete.

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.

FindServicePoint(Uri)
Obsolete.

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.

FindServicePoint(String, IWebProxy)
Obsolete.

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uniform Resource Identifier (URI).

FindServicePoint(Uri, IWebProxy)

Source:
ServicePointManager.cs
Source:
ServicePointManager.cs
Source:
ServicePointManager.cs

Caution

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

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.

C#
public static System.Net.ServicePoint FindServicePoint(Uri address, System.Net.IWebProxy? proxy);
C#
[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);
C#
public static System.Net.ServicePoint FindServicePoint(Uri address, System.Net.IWebProxy proxy);

Parameters

address
Uri

A Uri object that contains the address of the Internet resource to contact.

proxy
IWebProxy

The proxy data for this request.

Returns

The ServicePoint object that manages communications for the request.

Attributes

Exceptions

address is null.

The maximum number of ServicePoint objects defined in MaxServicePoints has been reached.

Remarks

The FindServicePoint method returns the ServicePoint object associated with the specified Internet host name. If no ServicePoint object exists for that host, the ServicePointManager object creates one.

See also

Applies to

.NET 10 és más verziók
Termék Verziók (Elavult)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 9, 10 (6, 7, 8)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

FindServicePoint(Uri)

Source:
ServicePointManager.cs
Source:
ServicePointManager.cs
Source:
ServicePointManager.cs

Caution

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

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uri object.

C#
public static System.Net.ServicePoint FindServicePoint(Uri address);
C#
[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);

Parameters

address
Uri

The Uri object of the Internet resource to contact.

Returns

The ServicePoint object that manages communications for the request.

Attributes

Exceptions

address is null.

The maximum number of ServicePoint objects defined in MaxServicePoints has been reached.

Remarks

The FindServicePoint method returns the ServicePoint object associated with the specified Internet host name. If no ServicePoint object exists for that host, the ServicePointManager object creates one.

See also

Applies to

.NET 10 és más verziók
Termék Verziók (Elavult)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 9, 10 (6, 7, 8)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

FindServicePoint(String, IWebProxy)

Source:
ServicePointManager.cs
Source:
ServicePointManager.cs
Source:
ServicePointManager.cs

Caution

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

Finds an existing ServicePoint object or creates a new ServicePoint object to manage communications with the specified Uniform Resource Identifier (URI).

C#
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy? proxy);
C#
[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);
C#
public static System.Net.ServicePoint FindServicePoint(string uriString, System.Net.IWebProxy proxy);

Parameters

uriString
String

The URI of the Internet resource to be contacted.

proxy
IWebProxy

The proxy data for this request.

Returns

The ServicePoint object that manages communications for the request.

Attributes

Exceptions

The URI specified in uriString is invalid.

The maximum number of ServicePoint objects defined in MaxServicePoints has been reached.

Examples

The following code example demonstrates calling this method to access a ServicePoint object.

C#
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/");
}

Remarks

The FindServicePoint method returns the ServicePoint object associated with the specified Internet host name. If no ServicePoint object exists for that host, the ServicePointManager object creates one.

See also

Applies to

.NET 10 és más verziók
Termék Verziók (Elavult)
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 9, 10 (6, 7, 8)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1