HttpWebResponse.GetResponseStream メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpWebResponse.GetResponseStream メソッドの意味・解説 

HttpWebResponse.GetResponseStream メソッド

サーバーから応答本文読み取るために使用するストリーム取得します

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

Public Overrides Function
 GetResponseStream As Stream
Dim instance As HttpWebResponse
Dim returnValue As Stream

returnValue = instance.GetResponseStream
public override Stream GetResponseStream ()
public:
virtual Stream^ GetResponseStream () override
public Stream GetResponseStream ()
public override function GetResponseStream
 () : Stream

戻り値
応答本文格納している Stream

例外例外
例外種類条件

ProtocolViolationException

応答ストリームがありません。

ObjectDisposedException

現在のインスタンス破棄されています。

解説解説
使用例使用例

GetResponseStream使用してサーバーから応答読み取るための Stream インスタンス返す方法の例を次に示します

' Creates an HttpWebRequest for the specified URL. 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url),
 HttpWebRequest)
' Sends the request and waits for a response.            
Dim myHttpWebResponse As HttpWebResponse =
 CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
' Calls the method GetResponseStream to return the stream associated
 with the response.
Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
' Pipes the response stream to a higher level stream reader with the
 required encoding format. 
Dim readStream As New StreamReader(receiveStream,
 encode)
Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "Response
 stream received")
Dim read(256) As [Char]
' Reads 256 characters at a time.    
Dim count As Integer = readStream.Read(read,
 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0
    ' Dumps the 256 characters to a string and displays the string to
 the console.
    Dim str As New [String](read,
 0, count)
    Console.Write(str)
    count = readStream.Read(read, 0, 256)
End While
Console.WriteLine("")
' Releases the resources of the Stream.
readStream.Close()
 ' Releases the resources of the response.
myHttpWebResponse.Close()
// Creates an HttpWebRequest with the specified URL. 
    HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
    // Sends the HttpWebRequest and waits for the response.        
    
    HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
 
    // Gets the stream associated with the response.
    Stream receiveStream = myHttpWebResponse.GetResponseStream();
    Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
    // Pipes the stream to a higher level stream reader with the required
 encoding format. 
    StreamReader readStream = new StreamReader( receiveStream,
 encode );
Console.WriteLine("\r\nResponse stream received.");
    Char[] read = new Char[256];
    // Reads 256 characters at a time.    
    int count = readStream.Read( read, 0, 256 );
    Console.WriteLine("HTML...\r\n");
    while (count > 0) 
        {
            // Dumps the 256 characters on a string and displays the
 string to the console.
            String str = new String(read, 0, count);
            Console.Write(str);
            count = readStream.Read(read, 0, 256);
        }
    Console.WriteLine("");
    // Releases the resources of the response.
    myHttpWebResponse.Close();
    // Releases the resources of the Stream.
    readStream.Close();
// Creates an HttpWebRequest with the specified URL.
HttpWebRequest^ myHttpWebRequest = (HttpWebRequest^)( WebRequest::Create( url ) );
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse^ myHttpWebResponse = (HttpWebResponse^)( myHttpWebRequest->GetResponse()
 );
// Gets the stream associated with the response.
Stream^ receiveStream = myHttpWebResponse->GetResponseStream();
Encoding^ encode = System::Text::Encoding::GetEncoding( "utf-8" );
// Pipes the stream to a higher level stream reader with the required
 encoding format.
StreamReader^ readStream = gcnew StreamReader( receiveStream,encode );
Console::WriteLine( "\r\nResponse stream received." );
array<Char>^ read = gcnew array<Char>(256);
// Reads 256 characters at a time.
int count = readStream->Read( read, 0, 256 );
Console::WriteLine( "HTML...\r\n" );
while ( count > 0 )
{
   // Dumps the 256 characters on a String* and displays the String*
 to the console.
   String^ str = gcnew String( read,0,count );
   Console::Write( str );
   count = readStream->Read( read, 0, 256 );
}
Console::WriteLine( "" );
// Releases the resources of the response.
myHttpWebResponse->Close();
// Releases the resources of the Stream.
readStream->Close();
// Creates an HttpWebRequest with the specified URL. 
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
    WebRequest.Create(url);

// Sends the HttpWebRequest and waits for the response.            
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
    myHttpWebRequest.GetResponse();

// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

// Pipes the stream to a higher level stream reader with the 
// required encoding format. 
StreamReader readStream = new StreamReader(receiveStream, encode);
Console.WriteLine("\r\nResponse stream received.");
char read[] = new char[256];

// Reads 256 characters at a time.    
int count = readStream.Read(read, 0, 256);

Console.WriteLine("HTML...\r\n");
while (count > 0) {
    // Dumps the 256 characters on a string and displays the
    // string to the console.
    String str = new String(read, 0, count);
    Console.Write(str);
    count = readStream.Read(read, 0, 256);
}
Console.WriteLine("");
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

HttpWebResponse.GetResponseStream メソッドのお隣キーワード
検索ランキング

   

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



HttpWebResponse.GetResponseStream メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS