次の方法で共有


HttpWebResponse クラス

WebResponse クラスの HTTP 固有の実装を提供します。

この型のすべてのメンバの一覧については、HttpWebResponse メンバ を参照してください。

System.Object
   System.MarshalByRefObject
      System.Net.WebResponse
         System.Net.HttpWebResponse

<Serializable>
Public Class HttpWebResponse   Inherits WebResponse
[C#]
[Serializable]
public class HttpWebResponse : WebResponse
[C++]
[Serializable]
public __gc class HttpWebResponse : public WebResponse
[JScript]
public
   Serializable
class HttpWebResponse extends WebResponse

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

解説

このクラスには、 WebResponse クラスのプロパティとメソッドを HTTP 固有の方法で使用するためのサポートが含まれています。 HttpWebResponse クラスは、HTTP 要求を送信したり、HTTP 応答を受信したりする HTTP スタンドアロン クライアント アプリケーションを構築する際に使用します。

メモ    HttpWebResponseHttpResponse を混同しないでください。後者は、ASP.NET アプリケーションで使用し、そのメソッドおよびプロパティは ASP.NET の組み込み HttpResponse オブジェクトを使用して公開されます。

HttpWebResponse クラスのインスタンスは直接作成しないでください。代わりに、 HttpWebRequest.GetResponse への呼び出しによって返されるインスタンスを使用してください。応答を閉じて、再使用のための接続を解放するために Stream.Close メソッドまたは HttpWebResponse.Close メソッドを呼び出す必要があります。 Stream.CloseHttpWebResponse.Close の両方を呼び出す必要はありません。ただし、両方呼び出してもエラーは発生しません。

インターネット リソースから返される共通ヘッダー情報は、クラスのプロパティとして公開されます。全一覧については、次の表を参照してください。他のヘッダーは、 Headers プロパティから、名前/値ペアとして読み取ることができます。

HttpWebResponse クラスのプロパティを通じて使用できる共通の HTTP ヘッダーを次の表に示します。

ヘッダー プロパティ
Content-Encoding ContentEncoding
Content-Length ContentLength
Content-Type ContentType
Last-Modified LastModified
Server Server

GetResponseStream メソッドを呼び出すことにより、インターネット リソースからの応答の内容が、 Stream として返されます。

使用例

HttpWebRequest から HttpWebResponse を返す例を次に示します。

 
Dim HttpWReq As HttpWebRequest = _
   CType(WebRequest.Create("https://www.contoso.com"), HttpWebRequest)
       
Dim HttpWResp As HttpWebResponse = _
   CType(HttpWReq.GetResponse(), HttpWebResponse)
' Insert code that uses the response object.
HttpWResp.Close()

[C#] 
HttpWebRequest HttpWReq = 
(HttpWebRequest)WebRequest.Create("https://www.contoso.com");

HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
// Insert code that uses the response object.
HttpWResp.Close();

[C++] 
HttpWebRequest* HttpWReq = 
dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"https://www.contoso.com"));

HttpWebResponse* HttpWResp = dynamic_cast<HttpWebResponse*>(HttpWReq->GetResponse());
// Insert code that uses the response object.
HttpWResp->Close();

[JScript] 
var httpWReq : HttpWebRequest = HttpWebRequest(WebRequest.Create("https://www.contoso.com"))
       
var httpWResp : HttpWebResponse = HttpWebResponse(httpWReq.GetResponse())
// Insert code to use response object.
httpWResp.Close()

必要条件

名前空間: System.Net

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

アセンブリ: System (System.dll 内)

参照

HttpWebResponse メンバ | System.Net 名前空間 | WebResponse