IWebProxy.GetProxy(Uri) 메서드

정의

프록시의 URI를 반환합니다.

public:
 Uri ^ GetProxy(Uri ^ destination);
public Uri GetProxy(Uri destination);
public Uri? GetProxy(Uri destination);
abstract member GetProxy : Uri -> Uri
Public Function GetProxy (destination As Uri) As Uri

매개 변수

destination
Uri

요청된 인터넷 리소스를 지정하는 A Uri 입니다.

반품

Uri

Uri 연결할 destination때 사용되는 프록시의 URI가 들어 있는 인스턴스입니다. 그렇지 않으면 null 또는 destination 자체입니다.

예제

다음 예제에서는 이 메서드를 사용하여 GetProxy 인터넷 리소스에 HttpClient 액세스하는 데 사용하는 URI를 반환합니다.

WebProxy_Interface webProxy_Interface = new WebProxy_Interface(new Uri("http://proxy.example.com"));

webProxy_Interface.Credentials = new NetworkCredential("myusername", "mypassword");

Uri testUri = new Uri("http://www.contoso.com");

// Determine whether the Web proxy can be bypassed for the site "http://www.contoso.com".
if(webProxy_Interface.IsBypassed(testUri))
{
    Console.WriteLine("Web Proxy is by passed");
}
else
{
    Uri? webProxyServer = webProxy_Interface.GetProxy(testUri);
    // In general, we wouldn't expect the condition (`webProxyServer! == testUri`) true here, if  IsBypassed returns `false`.
    // However, technically our interface can allow that.
    if (webProxyServer is null || webProxyServer! == testUri)
    {
        Console.WriteLine("Web proxy is bypassed");
    }
    else
    {
        Console.WriteLine("Web proxy is not bypassed");
        Console.WriteLine($"The web proxy is: {webProxyServer!}");
    }
}

 Public Shared Sub Main()
     Dim webProxy_Interface As New WebProxy_Interface(New Uri("http://proxy.example.com"))
     
     webProxy_Interface.Credentials = New NetworkCredential("myusername", "mypassword")
     
     Console.WriteLine("The web proxy is : {0}", webProxy_Interface.GetProxy(New Uri("http://www.contoso.com")))
     
     'Determine whether the Web proxy can be bypassed for the site "http://www.contoso.com".
 console.writeline("For the Uri http://www.contoso.com , the ")
     If webProxy_Interface.IsBypassed(New Uri("http://www.contoso.com")) Then
         Console.WriteLine("webproxy is by passed")
     Else
         Console.WriteLine("webproxy is not bypassed")
     End If 
 End Sub

설명

이 메서드는 GetProxy 매개 변수에 지정된 인터넷 리소스에 대한 요청을 처리하는 프록시 서버의 URI를 destination 반환합니다. 메서드가 GetProxy null 또는 destination 자체를 반환하는 경우 프록시는 호스트에 연락하는 데 사용되지 않으며 요청이 서버에 직접 전달됩니다.

적용 대상