WebRequest クラス
アセンブリ: System (system.dll 内)

<SerializableAttribute> _ Public MustInherit Class WebRequest Inherits MarshalByRefObject Implements ISerializable
[SerializableAttribute] public ref class WebRequest abstract : public MarshalByRefObject, ISerializable

WebRequest は、インターネットからのデータにアクセスするための .NET Framework の要求/応答モデル用の abstract 基本クラスです。要求/応答モデルを使用するアプリケーションは、プロトコルに寛容な方法で、インターネットからデータを要求できます。この場合、アプリケーションは WebRequest クラスのインスタンスで動作し、プロトコルに固有な派生クラスが要求の詳細を実行します。
要求は、アプリケーションからサーバー上の Web ページなどの特定の URI に送信されます。URI は、そのアプリケーション用に登録されている WebRequest 派生クラスの一覧から、作成する適切な派生クラスを決定します。通常、WebRequest 派生クラスは、HTTP または FTP などの固有のプロトコルを処理するために登録されていますが、固有なサーバーまたはサーバーのパスへの要求を処理するために登録することもできます。
WebRequest クラスは、インターネット リソースへのアクセス中にエラーが発生したときに WebException をスローします。WebException.Status プロパティは、エラーの原因を示す WebExceptionStatus 値の 1 つです。WebException.Status が WebExceptionStatus.ProtocolError の場合、Response プロパティには、インターネット リソースから受信した WebResponse が格納されます。
WebRequest クラスは abstract クラスであるため、実行時の WebRequest インスタンスの実際の動作は、System.Net.WebRequest.Create メソッドで返される派生クラスによって決まります。既定値および例外の詳細については、HttpWebRequest や FileWebRequest などの派生クラスの説明を参照してください。
![]() |
---|
新しい WebRequest インスタンスを初期化するには、Create メソッドを使用します。WebRequest コンストラクタは使用しないでください。 |
![]() |
---|
WebRequest オブジェクトを作成するアプリケーションが通常のユーザーの資格情報で実行されている場合、アクセス許可がそのユーザーに明示的に与えられていない限り、アプリケーションは、ローカル コンピュータ ストアにインストールされた証明書にアクセスできません。 |

WebRequest インスタンスを作成し、応答を返す方法を次の例に示します。
Imports System Imports System.IO Imports System.Net Imports System.Text Namespace Examples.System.Net Public Class WebRequestGetExample Public Shared Sub Main() ' Create a request for the URL. Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html") ' If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials ' Get the response. Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse) ' Display the status. Console.WriteLine(response.StatusDescription) ' Get the stream containing content returned by the server. Dim dataStream As Stream = response.GetResponseStream() ' Open the stream using a StreamReader for easy access. Dim reader As New StreamReader(dataStream) ' Read the content. Dim responseFromServer As String = reader.ReadToEnd() ' Display the content. Console.WriteLine(responseFromServer) ' Cleanup the streams and the response. reader.Close() dataStream.Close() response.Close() End Sub 'Main End Class 'WebRequestGetExample End Namespace
using System; using System.IO; using System.Net; using System.Text; namespace Examples.System.Net { public class WebRequestGetExample { public static void Main () { // Create a request for the URL. WebRequest request = WebRequest.Create ("http://www.contoso.com/default.html"); // If required by the server, set the credentials. request.Credentials = CredentialCache.DefaultCredentials; // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse (); // Display the status. Console.WriteLine (response.StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream (); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader (dataStream); // Read the content. string responseFromServer = reader.ReadToEnd (); // Display the content. Console.WriteLine (responseFromServer); // Cleanup the streams and the response. reader.Close (); dataStream.Close (); response.Close (); } } }
#using <System.dll> using namespace System; using namespace System::IO; using namespace System::Net; using namespace System::Text; int main() { // Create a request for the URL. WebRequest^ request = WebRequest::Create( "http://www.contoso.com/default.html" ); // If required by the server, set the credentials. request->Credentials = CredentialCache::DefaultCredentials; // Get the response. HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse()); // Display the status. Console::WriteLine( response->StatusDescription ); // Get the stream containing content returned by the server. Stream^ dataStream = response->GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader^ reader = gcnew StreamReader( dataStream ); // Read the content. String^ responseFromServer = reader->ReadToEnd(); // Display the content. Console::WriteLine( responseFromServer ); // Cleanup the streams and the response. reader->Close(); dataStream->Close(); response->Close(); }


System.MarshalByRefObject
System.Net.WebRequest
System.Net.FileWebRequest
System.Net.FtpWebRequest
System.Net.HttpWebRequest


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebRequest コンストラクタ ()
アセンブリ: System (system.dll 内)



WebRequest クラスで Create メソッドを呼び出して、WebRequest インスタンスを作成する方法を次の例に示します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


WebRequest コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: System (system.dll 内)

Protected Sub New ( _ serializationInfo As SerializationInfo, _ streamingContext As StreamingContext _ )
Dim serializationInfo As SerializationInfo Dim streamingContext As StreamingContext Dim instance As New WebRequest(serializationInfo, streamingContext)
protected:
WebRequest (
SerializationInfo^ serializationInfo,
StreamingContext streamingContext
)
protected function WebRequest ( serializationInfo : SerializationInfo, streamingContext : StreamingContext )



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


WebRequest コンストラクタ

名前 | 説明 |
---|---|
WebRequest () | WebRequest クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
WebRequest (SerializationInfo, StreamingContext) | SerializationInfo クラスと StreamingContext クラスの指定したインスタンスから、WebRequest クラスの新しいインスタンスを初期化します。 |

WebRequest プロパティ

名前 | 説明 | |
---|---|---|
![]() ![]() | ImpersonationLevel | 現在の要求に対する偽装レベルを取得または設定します。 |
![]() ![]() ![]() ![]() ![]() ![]() | UseDefaultCredentials | 派生クラスでオーバーライドされる場合、DefaultCredentials が要求と共に送信されるかどうかを制御する Boolean 値を取得または設定します。 |

WebRequest メソッド


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | GetObjectData | SerializationInfo に、オブジェクトをシリアル化するために必要なデータを設定します。 |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | 派生クラスでオーバーライドされる場合、SerializationInfo インスタンスに、WebRequest をシリアル化するために必要なデータを設定します。 |

WebRequest メンバ
URI (Uniform Resource Identifier) への要求を行います。これは abstract クラスです。
WebRequest データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() ![]() | ImpersonationLevel | 現在の要求に対する偽装レベルを取得または設定します。 |
![]() ![]() ![]() ![]() ![]() ![]() | UseDefaultCredentials | 派生クラスでオーバーライドされる場合、DefaultCredentials が要求と共に送信されるかどうかを制御する Boolean 値を取得または設定します。 |


名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | GetObjectData | SerializationInfo に、オブジェクトをシリアル化するために必要なデータを設定します。 |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Runtime.Serialization.ISerializable.GetObjectData | 派生クラスでオーバーライドされる場合、SerializationInfo インスタンスに、WebRequest をシリアル化するために必要なデータを設定します。 |

Weblioに収録されているすべての辞書からWebRequestを検索する場合は、下記のリンクをクリックしてください。

- WebRequestのページへのリンク