IWebProxy.GetProxy(Uri) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回 Proxy 的 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
參數
傳回
Uri實例,包含用來連絡destination
之 Proxy 的 URI,否則為 null 或destination
本身。
範例
下列範例會 GetProxy 使用 方法來傳回 用來存取因特網資源的 URI HttpClient 。
WebProxy_Interface^ webProxy_Interface = gcnew WebProxy_Interface( gcnew Uri( "http://proxy.example.com" ) );
webProxy_Interface->Credentials = gcnew NetworkCredential( "myusername", "mypassword" );
Console::WriteLine( "The web proxy is : {0}", webProxy_Interface->GetProxy( gcnew Uri( "http://www.contoso.com" ) ) );
// Check if the webproxy can ne bypassed for the site "http://www.contoso.com".
if ( webProxy_Interface->IsBypassed( gcnew Uri( "http://www.contoso.com" ) ) )
{
Console::WriteLine( "Web Proxy is by passed" );
}
else
{
Console::WriteLine( "Web Proxy is not by passed" );
}
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 會傳回 Proxy 伺服器的 URI,該伺服器會處理參數中所 destination
指定因特網資源的要求。 GetProxy如果方法傳回 null 或destination
本身,則 Proxy 不會用來連絡主機,而且要求會直接傳遞至伺服器。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應