Bagikan melalui


WebProxy.GetProxy(Uri) Metode

Definisi

Mengembalikan URI yang diproksi untuk permintaan.

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

Parameter

destination
Uri

Instans Uri sumber daya Internet yang diminta.

Mengembalikan

Uri

Instans Uri sumber daya Internet, jika sumber daya ada dalam daftar bypass; jika tidak, Uri instans proksi.

Penerapan

Pengecualian

Parameternya destination adalah null.

Contoh

Contoh kode berikut membuat WebProxy objek dan memanggil metode ini untuk mendapatkan proksi yang dipilih untuk sumber daya.

// The following method creates a WebProxy object that uses Internet Explorer's  
// detected script if it is found in the registry; otherwise, it 
// tries to use Web proxy auto-discovery to set the proxy used for
// the request.
void CheckAutoGlobalProxyForRequest( Uri^ resource )
{
   WebProxy^ proxy = gcnew WebProxy;
   
   // Display the proxy's properties.
   DisplayProxyProperties( proxy );
   
   // See what proxy is used for the resource.
   Uri^ resourceProxy = proxy->GetProxy( resource );
   
   // Test to see whether a proxy was selected.
   if ( resourceProxy == resource )
   {
      Console::WriteLine( "No proxy for {0}", resource );
   }
   else
   {
      Console::WriteLine( "Proxy for {0} is {1}", resource, resourceProxy );
   }
}
// The following method creates a WebProxy object that uses Internet Explorer's
// detected script if it is found in the registry; otherwise, it
// tries to use Web proxy auto-discovery to set the proxy used for
// the request.

public static void CheckAutoGlobalProxyForRequest(Uri resource)
{
    WebProxy proxy = new WebProxy();

    // Display the proxy's properties.
    DisplayProxyProperties(proxy);

    // See what proxy is used for the resource.
    Uri resourceProxy = proxy.GetProxy(resource);

    // Test to see whether a proxy was selected.
    if (resourceProxy == resource)
    {
        Console.WriteLine("No proxy for {0}", resource);
    }
    else
    {
        Console.WriteLine("Proxy for {0} is {1}", resource.OriginalString,
            resourceProxy.ToString());
    }
}

Keterangan

Metode mengembalikan GetProxy URI yang HttpClient digunakan instans untuk mengakses sumber daya Internet.

GetProxydestination membandingkan dengan konten BypassList, menggunakan IsBypassed metode . Jika IsBypassed mengembalikan true, GetProxy mengembalikan dan HttpClient instans destination tidak menggunakan server proksi.

Jika destination tidak ada di BypassList, HttpClient instans menggunakan server proksi dan Address properti dikembalikan.

Berlaku untuk