HttpWebRequest.Proxy 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
요청에 대한 프록시 정보를 가져오거나 설정합니다.
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 하여 설정합니다.
예외
Proxy이 null로 설정됩니다.
요청이 호출GetRequestStream(), BeginGetRequestStream(AsyncCallback, Object)또는 GetResponse()BeginGetResponse(AsyncCallback, Object).
호출자에게 요청된 작업에 대한 권한이 없습니다.
예제
다음 코드 예제에서는 메서드를 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 != 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)
설명
주의
WebRequest, HttpWebRequest, ServicePoint및 WebClient 사용되지 않으므로 새 개발에 사용하면 안 됩니다.
HttpClient를 대신 사용하세요.
이 속성은 Proxy 인터넷 리소스에 대한 요청을 처리하는 데 사용할 개체를 식별 WebProxy 합니다. 프록시를 사용하지 않도록 지정하려면 Proxy 속성을 GlobalProxySelection.GetEmptyWebProxy 메서드에서 반환된 프록시 인스턴스로 설정합니다.
로컬 컴퓨터 또는 애플리케이션 구성 파일은 기본 프록시를 사용할지 지정할 수 있습니다. 속성이 Proxy 지정된 경우 속성의 Proxy 프록시 설정은 로컬 컴퓨터 또는 애플리케이션 구성 파일을 재정의 HttpWebRequest 하고 인스턴스는 지정된 프록시 설정을 사용합니다. 구성 파일에 Proxy 프록시가 지정되지 않고 속성이 지정되지 HttpWebRequest 않은 경우 클래스는 로컬 컴퓨터의 인터넷 옵션에서 상속된 프록시 설정을 사용합니다. 인터넷 옵션에 프록시 설정이 없으면 요청이 서버로 직접 전송됩니다.
HttpWebRequest 클래스는 로컬 프록시 바이패스를 지원합니다. 클래스는 다음 조건이 충족되는 경우 대상을 로컬로 간주합니다.
대상에는 플랫 이름이 포함되어 있습니다(URL에 점 없음).
대상에 루프백 주소(Loopback 또는 IPv6Loopback)가 포함되거나 대상에 로컬 컴퓨터에 할당된 주소가 포함됩니다 IPAddress .
대상의 도메인 접미사는 로컬 컴퓨터의 도메인 접미사(DomainName)와 일치합니다.
요청이 Proxy 시작된 후 , BeginGetRequestStream또는 GetResponseBeginGetResponse 메서드를 호출GetRequestStream하여 속성을 변경하면 .InvalidOperationException 프록시 요소에 대한 자세한 내용은 <를 참조하세요.