HttpWebRequest.Proxy 속성

정의

요청에 대한 프록시 정보를 가져오거나 설정합니다.

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

속성 값

요청을 프록시하는 데 사용할 IWebProxy 개체입니다. 기본값은 Select 속성을 호출함으로써 설정됩니다.

예외

Proxynull로 설정됩니다.

호출자에게 요청된 작업에 대한 권한이 없는 경우

예제

다음 코드 예제에서는 메서드를 Proxy 사용하여 요청에 대한 프록시 정보를 가져옵니다.

// 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)

설명

Proxy 속성은 인터넷 리소스에 대한 요청을 처리하는 데 사용할 WebProxy 개체를 식별합니다. 프록시를 사용하지 않도록 지정하려면 Proxy 속성을 GlobalProxySelection.GetEmptyWebProxy 메서드에서 반환된 프록시 인스턴스로 설정합니다.

로컬 컴퓨터 또는 애플리케이션 구성 파일을 기본 프록시를 사용할 수 있는지 지정할 수 있습니다. 경우는 Proxy 속성을 지정 하면에서 프록시 설정을 Proxy 로컬 컴퓨터 또는 애플리케이션 구성 파일을 재정의 하는 속성 및 HttpWebRequest 인스턴스는 지정 된 프록시 설정을 사용 합니다. 구성 파일에 Proxy 프록시가 지정되지 않고 속성이 지정 HttpWebRequest 되지 않은 경우 클래스는 로컬 컴퓨터의 인터넷 Explorer 상속된 프록시 설정을 사용합니다. 인터넷 Explorer 프록시 설정이 없으면 요청이 서버로 직접 전송됩니다.

클래스는 HttpWebRequest 바이패스 목록이 인터넷 Explorer 직접 구문 분석되는 것과 Explorer 인터넷에서 상속된 와일드카드 문자로 프록시 바이패스 목록을 구문 분석합니다. 예를 들어 클래스는 HttpWebRequest 인터넷 Explorer "nt*"의 바이패스 목록을 "nt.*"의 정규식으로 구문 분석합니다. 따라서 "http://nt.com"의 URL은 클래스를 사용하고 HttpWebRequest 인터넷 Explorer 사용하여 프록시를 바이패스합니다.

HttpWebRequest 클래스는 로컬 프록시 바이패스를 지원합니다. 클래스는 다음 조건이 충족되는 경우 대상을 로컬로 간주합니다.

  • 대상에는 플랫 이름이 포함되어 있습니다(URL에 점 없음).

  • 대상에 루프백 주소(Loopback 또는 IPv6Loopback)가 포함되거나 대상에 로컬 컴퓨터에 할당된 IPAddress가 포함됩니다.

  • 대상의 도메인 접미사는 로컬 컴퓨터의 도메인 접미사(DomainName)와 일치합니다.

Proxy, , BeginGetRequestStreamGetResponse또는 BeginGetResponse 메서드를 호출GetRequestStream하여 요청이 시작된 후 속성을 변경하면 가 throw됩니다InvalidOperationException. 프록시 요소에 대한 자세한 내용은 < defaultProxy> 요소(네트워크 설정).

적용 대상

추가 정보