HttpWebRequest.Proxy プロパティ
アセンブリ: System (system.dll 内)

public: virtual property IWebProxy^ Proxy { IWebProxy^ get () override; void set (IWebProxy^ value) override; }
/** @property */ public IWebProxy get_Proxy () /** @property */ public void set_Proxy (IWebProxy value)
public override function get Proxy () : IWebProxy public override function set Proxy (value : IWebProxy)
要求に対するプロキシで使用する IWebProxy オブジェクト。既定値は GlobalProxySelection.Select プロパティを呼び出して設定します。


Proxy プロパティは、インターネット リソースへの要求を処理するために使用する WebProxy オブジェクトを識別します。プロキシが使用されないように指定するには、GlobalProxySelection.GetEmptyWebProxy メソッドが返すプロキシ インスタンスに Proxy プロパティを設定します。
GetRequestStream、BeginGetRequestStream、GetResponse、または BeginGetResponse の各メソッドの呼び出しによって開始した要求の後に Proxy プロパティを変更すると、InvalidOperationException がスローされます。プロキシ要素については、「DefaultProxy Element (Network Settings)」を参照してください。

要求に対して使用するプロキシ情報を、Proxy メソッドを使って取得するコード例を次に示します。
' Create a new request to the mentioned URL. Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest) Dim myProxy As New WebProxy() ' Obtain the 'Proxy' of the Default browser. myProxy = CType(myWebRequest.Proxy, WebProxy) ' Print the Proxy Url to the console. Console.WriteLine(ControlChars.Cr + "The actual default Proxy settings are {0}", myProxy.Address) Try 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 proxyAddress = Console.ReadLine() If proxyAddress.Length = 0 Then myWebRequest.Proxy = myProxy Else Console.WriteLine(ControlChars.Cr + "Please enter the Credentials") 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)
// Create a new request to the mentioned URL. HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); WebProxy myProxy=new WebProxy(); // Obtain the 'Proxy' of the Default browser. myProxy=(WebProxy)myWebRequest.Proxy; // Print the Proxy Url to the console. Console.WriteLine("\nThe actual default Proxy settings are {0}",myProxy.Address); try { Console.WriteLine("\nPlease enter the new Proxy Address that is to be set:"); Console.WriteLine("(Example:http://myproxy.example.com:port)"); string proxyAddress; 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=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. HttpWebRequest^ myWebRequest = (HttpWebRequest^)( WebRequest::Create( "http://www.microsoft.com" ) ); WebProxy^ myProxy = gcnew WebProxy; // Obtain the 'Proxy' of the Default browser. myProxy = (WebProxy^)( myWebRequest->Proxy ); // Print the Proxy Url to the console. Console::WriteLine( "\nThe actual default Proxy settings are {0}", myProxy->Address ); try { Console::WriteLine( "\nPlease enter the new Proxy Address that is to be set:" ); Console::WriteLine( "(Example:http://myproxy.example.com:port)" ); String^ proxyAddress; 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"); WebProxy myProxy = new WebProxy(); // Obtain the 'Proxy' of the Default browser. myProxy = (WebProxy)myWebRequest.get_Proxy(); // Print the Proxy Url to the console. Console.WriteLine("\nThe actual default Proxy settings are {0}", myProxy.get_Address()); try { Console.WriteLine("\nPlease enter the new Proxy Address " +" that is to be set:"); Console.WriteLine("(Example:http://myproxy.com:port)"); String proxyAddress; 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 = new Uri(proxyAddress); // Associate the newUri object to 'myProxy' object so that // new myProxy settings can be set. myProxy.set_Address(newUri); // Create a NetworkCredential object and associate it with // the Proxy property of request object. myProxy.set_Credentials(new NetworkCredential(username , password)); myWebRequest.set_Proxy(myProxy); } Console.WriteLine("\nThe Address of the new Proxy settings " + "are {0}", myProxy.get_Address()); HttpWebResponse myWebResponse = (HttpWebResponse) myWebRequest.GetResponse();


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からHttpWebRequest.Proxy プロパティを検索する場合は、下記のリンクをクリックしてください。

- HttpWebRequest.Proxy プロパティのページへのリンク