HttpWebRequest.Proxy プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpWebRequest.Proxy プロパティの意味・解説 

HttpWebRequest.Proxy プロパティ

要求に対して使用するプロキシ情報取得または設定します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Property
 Proxy As IWebProxy
Dim instance As HttpWebRequest
Dim value As IWebProxy

value = instance.Proxy

instance.Proxy = value
public override IWebProxy Proxy { get; set;
 }
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)

プロパティ
要求対すプロキシ使用する IWebProxy オブジェクト既定値は GlobalProxySelection.Select プロパティ呼び出して設定します

例外例外
例外種類条件

ArgumentNullException

Proxynull 参照 (Visual Basic では Nothing) に設定されています。

InvalidOperationException

要求が GetRequestStream、BeginGetRequestStream、GetResponse、または BeginGetResponse の呼び出しにより既に開始されています。

SecurityException

要求され操作実行するためのアクセス許可呼び出し元にありません。

解説解説

Proxy プロパティは、インターネット リソースへの要求処理するために使用する WebProxy オブジェクト識別します。プロキシ使用されないように指定するには、GlobalProxySelection.GetEmptyWebProxy メソッド返すプロキシ インスタンスProxy プロパティ設定します

GetRequestStreamBeginGetRequestStreamGetResponse、または 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();
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpWebRequest.Proxy プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpWebRequest.Proxy プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpWebRequest.Proxy プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HttpWebRequest.Proxy プロパティ」の関連用語

HttpWebRequest.Proxy プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpWebRequest.Proxy プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS