HttpWebRequest.ServicePoint 属性    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取要用于请求的服务点。
public:
 property System::Net::ServicePoint ^ ServicePoint { System::Net::ServicePoint ^ get(); };public System.Net.ServicePoint ServicePoint { get; }member this.ServicePoint : System.Net.ServicePointPublic ReadOnly Property ServicePoint As ServicePoint属性值
表示与 Internet 资源的网络连接的 ServicePoint。
示例
private static void makeWebRequest(int hashCode, string Uri)
{
    HttpWebResponse res = null;
    // Make sure that the idle time has elapsed, so that a new
    // ServicePoint instance is created.
    Console.WriteLine("Sleeping for 2 sec.");
    Thread.Sleep(2000);
    try
    {
        // Create a request to the passed URI.
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Uri);
        Console.WriteLine("\nConnecting to " + Uri + " ............");
        // Get the response object.
        res = (HttpWebResponse)req.GetResponse();
        Console.WriteLine("Connected.\n");
        ServicePoint currentServicePoint = req.ServicePoint;
        // Display new service point properties.
        int currentHashCode = currentServicePoint.GetHashCode();
        Console.WriteLine("New service point hashcode: " + currentHashCode);
        Console.WriteLine("New service point max idle time: " + currentServicePoint.MaxIdleTime);
        Console.WriteLine("New service point is idle since " + currentServicePoint.IdleSince );
        // Check that a new ServicePoint instance has been created.
        if (hashCode == currentHashCode)
            Console.WriteLine("Service point reused.");
        else
            Console.WriteLine("A new service point created.") ;
    }
    catch (Exception e)
    {
        Console.WriteLine("Source : " + e.Source);
        Console.WriteLine("Message : " + e.Message);
    }
    finally
    {
        if (res != null)
            res.Close();
    }
}
Private Shared Sub makeWebRequest(ByVal hashCode As Integer, ByVal Uri As String)
    Dim res As HttpWebResponse = Nothing
    ' Make sure that the idle time has elapsed, so that a new 
    ' ServicePoint instance is created.
    Console.WriteLine("Sleeping for 2 sec.")
    Thread.Sleep(2000)
    Try
        ' Create a request to the passed URI.
        Dim req As HttpWebRequest = CType(WebRequest.Create(Uri), HttpWebRequest)
        Console.WriteLine((ControlChars.Lf + "Connecting to " + Uri + " ............"))
        ' Get the response object.
        res = CType(req.GetResponse(), HttpWebResponse)
        Console.WriteLine("Connected." + ControlChars.Lf)
        Dim currentServicePoint As ServicePoint = req.ServicePoint
        ' Display new service point properties.
        Dim currentHashCode As Integer = currentServicePoint.GetHashCode()
        Console.WriteLine(("New service point hashcode: " + currentHashCode.ToString()))
        Console.WriteLine(("New service point max idle time: " + currentServicePoint.MaxIdleTime.ToString()))
        Console.WriteLine(("New service point is idle since " + currentServicePoint.IdleSince.ToString()))
        ' Check that a new ServicePoint instance has been created.
        If hashCode = currentHashCode Then
            Console.WriteLine("Service point reused.")
        Else
            Console.WriteLine("A new service point created.")
        End If
    Catch e As Exception
        Console.WriteLine(("Source : " + e.Source))
        Console.WriteLine(("Message : " + e.Message))
    Finally
        If Not (res Is Nothing) Then
            res.Close()
        End If
    End Try
End Sub
注解
谨慎
              WebRequest、HttpWebRequest、ServicePoint和 WebClient 已过时,不应将其用于新开发。 请改用 HttpClient。
如果重定向请求,ServicePoint.Address 属性可能与 HttpWebRequest.Address 不同。