Share via


HttpWebRequest.Proxy Özellik

Tanım

İstek için ara sunucu bilgilerini alır veya ayarlar.

public:
 virtual property System::Net::IWebProxy ^ Proxy { System::Net::IWebProxy ^ get(); void set(System::Net::IWebProxy ^ value); };
public override System.Net.IWebProxy? Proxy { get; set; }
public override System.Net.IWebProxy Proxy { get; set; }
member this.Proxy : System.Net.IWebProxy with get, set
Public Overrides Property Proxy As IWebProxy

Özellik Değeri

İstekte IWebProxy ara sunucu olarak kullanılacak nesne. Varsayılan değer, özelliği çağrılarak Select ayarlanır.

Özel durumlar

Proxy olarak ayarlanır null.

Çağıranın istenen işlem için izni yok.

Örnekler

Aşağıdaki kod örneği, isteğin Proxy proxy bilgilerini almak için yöntemini kullanır.

// Create a new request to the mentioned URL.
HttpWebRequest ^ myWebRequest =
    (HttpWebRequest ^) (WebRequest::Create("http://www.microsoft.com"));

// Obtain the 'Proxy' of the  Default browser.  
IWebProxy ^ proxy = myWebRequest->Proxy;
// Print the Proxy Url to the console.
if (proxy) 
{
    Console::WriteLine("Proxy: {0}",
        proxy->GetProxy(myWebRequest->RequestUri));
} 
else 
{
    Console::WriteLine("Proxy is null; no proxy will be used");
}

WebProxy ^ myProxy = gcnew WebProxy;

Console::WriteLine("\nPlease enter the new Proxy Address that is to be set:");
Console::WriteLine("(Example:http://myproxy.example.com:port)");
String ^ proxyAddress;

try 
{
    proxyAddress = Console::ReadLine();
    if (proxyAddress->Length > 0) {
        Console::WriteLine("\nPlease enter the Credentials ");
        Console::WriteLine("Username:");
        String ^ username;
        username = Console::ReadLine();
        Console::WriteLine("\nPassword:");
        String ^ password;
        password = Console::ReadLine();
        // Create a new Uri object.
        Uri ^ newUri = gcnew Uri(proxyAddress);
        // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
        myProxy->Address = newUri;
        // Create a NetworkCredential object and associate it with the Proxy property of request object.
        myProxy->Credentials =
            gcnew NetworkCredential(username, password);
        myWebRequest->Proxy = myProxy;
    }
    Console::WriteLine("\nThe Address of the  new Proxy settings are {0}",
                  myProxy->Address);
    HttpWebResponse ^ myWebResponse =
        (HttpWebResponse ^) (myWebRequest->GetResponse());
// Create a new request to the mentioned URL.				
HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");

// Obtain the 'Proxy' of the  Default browser.
IWebProxy proxy = myWebRequest.Proxy;
// Print the Proxy Url to the console.
if (proxy != null)
{
    Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri));
}
else
{
    Console.WriteLine("Proxy is null; no proxy will be used");
}

WebProxy myProxy=new WebProxy();

Console.WriteLine("\nPlease enter the new Proxy Address that is to be set:");
Console.WriteLine("(Example:http://myproxy.example.com:port)");
string proxyAddress;

try
{
    proxyAddress =Console.ReadLine();
    if(proxyAddress.Length>0)
    {
        Console.WriteLine("\nPlease enter the Credentials (may not be needed)");
        Console.WriteLine("Username:");
        string username;
        username =Console.ReadLine();
        Console.WriteLine("\nPassword:");
        string password;
        password =Console.ReadLine();					
        // Create a new Uri object.
        Uri newUri=new Uri(proxyAddress);
        // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
        myProxy.Address=newUri;
        // Create a NetworkCredential object and associate it with the
        // Proxy property of request object.
        myProxy.Credentials=new NetworkCredential(username,password);
        myWebRequest.Proxy=myProxy;
    }
    Console.WriteLine("\nThe Address of the  new Proxy settings are {0}",myProxy.Address);
    HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();
' Create a new request to the mentioned URL.				
Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)

      ' Obtain the 'Proxy' of the  Default browser.  
      Dim proxy as IWebProxy = CType(myWebRequest.Proxy, IWebProxy)
      ' Print the Proxy Url to the console.
If Not proxy Is Nothing Then
    Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri))
Else
    Console.WriteLine("Proxy is null; no proxy will be used")
End If

Dim myProxy As New WebProxy()

Console.WriteLine(ControlChars.Cr + "Please enter the new Proxy Address that is to be set ")
Console.WriteLine("(Example:http://myproxy.example.com:port)")
Dim proxyAddress As String
Try
    proxyAddress = Console.ReadLine()
    If proxyAddress.Length = 0 Then
        myWebRequest.Proxy = myProxy
    Else
        Console.WriteLine(ControlChars.Cr + "Please enter the Credentials (may not be needed)")
        Console.WriteLine("Username:")
        Dim username As String
        username = Console.ReadLine()
        Console.WriteLine(ControlChars.Cr + "Password:")
        Dim password As String
        password = Console.ReadLine()
        ' Create a new Uri object.
        Dim newUri As New Uri(proxyAddress)
        ' Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
        myProxy.Address = newUri
        ' Create a NetworkCredential object and associate it with the Proxy property of request object.
        myProxy.Credentials = New NetworkCredential(username, password)
        myWebRequest.Proxy = myProxy
    End If
    Console.WriteLine(ControlChars.Cr + "The Address of the  new Proxy settings are {0}", myProxy.Address)
    Dim myWebResponse As HttpWebResponse = CType(myWebRequest.GetResponse(), HttpWebResponse)

Açıklamalar

özelliği, Proxy İnternet kaynaklarına WebProxy yönelik istekleri işlemek için kullanılacak nesneyi tanımlar. Hiçbir proxy kullanılmaması gerektiğini belirtmek için özelliğini yöntemi tarafından döndürülen proxy örneğine GlobalProxySelection.GetEmptyWebProxy ayarlayınProxy.

Yerel bilgisayar veya uygulama yapılandırma dosyası varsayılan bir ara sunucunun kullanılacağını belirtebilir. Proxy Özellik belirtilirse, özelliğindeki Proxy proxy ayarları yerel bilgisayarı veya uygulama yapılandırma dosyasını geçersiz kılar ve HttpWebRequest örnek belirtilen ara sunucu ayarlarını kullanır. Yapılandırma dosyasında proxy belirtilmezse ve Proxy özelliği belirtilmemişse, HttpWebRequest sınıf yerel bilgisayardaki İnternet seçeneklerinden devralınan ara sunucu ayarlarını kullanır. İnternet seçeneklerinde ara sunucu ayarları yoksa istek doğrudan sunucuya gönderilir.

HttpWebRequest sınıfı yerel ara sunucu atlamasını destekler. Sınıfı, aşağıdaki koşullardan herhangi biri karşılanırsa hedefi yerel olarak kabul eder:

  • Hedef düz bir ad içeriyor (URL'de nokta yok).

  • Hedef bir geri döngü adresi (Loopback veya IPv6Loopback) veya hedef yerel bilgisayara atanmış bir IPAddress adresi içerir.

  • Hedefin etki alanı soneki, yerel bilgisayarın etki alanı sonekiyle () eşleşirDomainName.

Proxy İstek başlatıldıktan sonra , , BeginGetRequestStreamGetResponseveya BeginGetResponse yöntemi çağrılarak GetRequestStreamözelliğinin değiştirilmesi bir InvalidOperationExceptionoluşturur. Proxy öğesi hakkında bilgi için bkz. < defaultProxy> Öğesi (Ağ Ayarları).

Şunlara uygulanır

Ayrıca bkz.