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

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

WebResponse.GetResponseStream メソッド

派生クラスオーバーライドされると、インターネット リソースからデータ ストリーム返します

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

Public Overridable Function
 GetResponseStream As Stream
Dim instance As WebResponse
Dim returnValue As Stream

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

戻り値
インターネット リソースからデータ読み取るための Stream クラスインスタンス

例外例外
解説解説
使用例使用例

GetResponseStream使用して、StreamReader インスタンス返す例を次に示します小さなローカル バッファは、StreamReader からデータ読み取り、そのデータコンソール出力するときに使用します

' Create a 'WebRequest' object with the specified url 
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' Call method 'GetResponseStream' to obtain stream associated with the
 response object
Dim ReceiveStream As Stream = myWebResponse.GetResponseStream()

Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")

' Pipe the stream to a higher level stream reader with the required
 encoding format.
Dim readStream As New StreamReader(ReceiveStream,
 encode)
Console.WriteLine(ControlChars.Cr + "Response stream received")
Dim read(256) As [Char]

' Read 256 charcters at a time    .
Dim count As Integer = readStream.Read(read,
 0, 256)
Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
While count > 0

    ' Dump the 256 characters on a string and display the string onto
 the console.
    Dim str As New [String](read,
 0, count)
    Console.Write(str)
    count = readStream.Read(read, 0, 256)

End While
Console.WriteLine("")

' Release the resources of stream object.
 readStream.Close()

 ' Release the resources of response object.
myWebResponse.Close()

    // Create a 'WebRequest' object with the specified url. 
 WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com");
 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Obtain a 'Stream' object associated with the response object.
Stream ReceiveStream = myWebResponse.GetResponseStream();
            
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

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

    // Read 256 charcters at a time.    
 int count = readStream.Read( read, 0, 256 );
    Console.WriteLine("HTML...\r\n");

while (count > 0) 
{
        // Dump the 256 characters on a string and display the string
 onto the console.
    String str = new String(read, 0, count);
    Console.Write(str);
    count = readStream.Read(read, 0, 256);
}

   Console.WriteLine("");
 // Release the resources of stream object.
 readStream.Close();

 // Release the resources of response object.
 myWebResponse.Close(); 

// Create a 'WebRequest' object with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com"
 );

// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Obtain a 'Stream' object associated with the response object.
Stream^ ReceiveStream = myWebResponse->GetResponseStream();

Encoding^ encode = System::Text::Encoding::GetEncoding( "utf-8" );

// Pipe the stream to a higher level stream reader with the required
 encoding format.
StreamReader^ readStream = gcnew StreamReader( ReceiveStream,encode );
Console::WriteLine( "\nResponse stream received" );
array<Char>^ read = gcnew array<Char>(256);

// Read 256 charcters at a time.
int count = readStream->Read( read, 0, 256 );
Console::WriteLine( "HTML...\r\n" );

while ( count > 0 )
{
   // Dump the 256 characters on a string and display the string onto
 the console.
   String^ str = gcnew String( read,0,count );
   Console::Write( str );
   count = readStream->Read( read, 0, 256 );
}

Console::WriteLine( "" );
// Release the resources of stream object.
readStream->Close();

// Release the resources of response object.
myWebResponse->Close();
// Create a 'WebRequest' object with the specified url. 
WebRequest myWebRequest = WebRequest.Create(
    "http://www.constoso.com");
// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();
// Obtain a 'Stream' object associated with the response object.
Stream receiveStream = myWebResponse.GetResponseStream();

Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipe the stream to a higher level stream reader with the required
 
// encoding format. 
StreamReader readStream = new StreamReader(receiveStream, encode);
Console.WriteLine("\nResponse stream received");
char read[] = new char[256];
// Read 256 charcters at a time.    
int count = readStream.Read(read, 0, 256);
Console.WriteLine("HTML...\r\n");

while (count > 0) {
    // Dump the 256 characters on a string and display the string 
    // onto the console.
    String str = new String(read, 0, count);
    Console.Write(str);
    count = readStream.Read(read, 0, 256);
}

Console.WriteLine("");
// Release the resources of stream object.
readStream.Close();
// Release the resources of response object.
myWebResponse.Close();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS