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)
{
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 クラスはローカル コンピューターのインターネット オプションから継承されたプロキシ設定を使用します。 インターネット オプションにプロキシ設定がない場合、要求はサーバーに直接送信されます。
HttpWebRequest クラスでは、ローカル プロキシのバイパスがサポートされています。 次のいずれかの条件が満たされている場合、クラスは宛先をローカルと見なします。
宛先にフラット名が含まれている (URL にドットがない)。
宛先にループバック アドレス (Loopback または IPv6Loopback) が含まれている、または宛先にローカル コンピューターに割り当てられた IPAddress が含まれている。
宛先のドメイン サフィックスが、ローカル コンピューターのドメイン サフィックス (DomainName) と一致する。
、、または メソッドをProxy呼び出して要求が開始された後に プロパティをGetRequestStreamGetResponseBeginGetRequestStream変更すると、 InvalidOperationExceptionがスローされます。BeginGetResponse プロキシ要素の詳細については、「 <」を参照してください。defaultProxy>要素 (ネットワーク設定)。
適用対象
こちらもご覧ください
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示