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

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

HttpWebRequest.GetResponse メソッド

インターネット リソースからの応答返します

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

Public Overrides Function
 GetResponse As WebResponse
Dim instance As HttpWebRequest
Dim returnValue As WebResponse

returnValue = instance.GetResponse
public override WebResponse GetResponse ()
public:
virtual WebResponse^ GetResponse () override
public WebResponse GetResponse ()
public override function GetResponse () : WebResponse

戻り値
インターネット リソースからの応答格納している WebResponse。

例外例外
例外種類条件

InvalidOperationException

ストリームが、既に BeginGetResponse の前回呼び出し使用されています。

または

TransferEncoding に値が設定され、SendChunked が false です。

ProtocolViolationException

MethodGET または HEAD で、ContentLength が 0 以上か、SendChunkedtrue です。

または

KeepAlivetrue で、AllowWriteStreamBuffering は false で、ContentLength は -1 で、SendChunkedfalse で、MethodPOST または PUT です。

NotSupportedException

要求キャッシュ検証コントロールで、この要求応答キャッシュから取得できることが示されましたが、この要求にはサーバー送信するデータ含まれています。データ送信する要求ではキャッシュ使用できません。この例外は、キャッシュ検証コントロール不適切カスタム実装使用した場合発生することがあります

WebException

Abort は既に呼び出されました。

または

要求タイムアウト時間経過しました

または

要求の処理中にエラー発生しました

解説解説
使用例使用例

要求への応答取得するコード例次に示します

Imports System
Imports System.Net
Imports System.Text
Imports System.IO


    Public Class Test

        ' Specify the URL to receive the request.
        Public Shared Sub
 Main(ByVal args() As String)
        Dim request As HttpWebRequest = CType(WebRequest.Create(args(0)),
 HttpWebRequest)


        ' Set some reasonable limits on resources used by this request
        request.MaximumAutomaticRedirections = 4
        request.MaximumResponseHeadersLength = 4

        ' Set credentials to use for this request.
        request.Credentials = CredentialCache.DefaultCredentials

        Dim response As HttpWebResponse = CType(request.GetResponse(),
 HttpWebResponse)

        Console.WriteLine("Content length is {0}",
 response.ContentLength)
        Console.WriteLine("Content type is {0}", response.ContentType)

        ' Get the stream associated with the response.
        Dim receiveStream As Stream = response.GetResponseStream()

        ' Pipes the stream to a higher level stream reader with the
 required encoding format. 
        Dim readStream As New
 StreamReader(receiveStream, Encoding.UTF8)

        Console.WriteLine("Response stream received.")
        Console.WriteLine(readStream.ReadToEnd())
        response.Close()
        readStream.Close()
    End Sub 'Main
End Class 'Test
'
'The output from this example will vary depending on the value passed
 into Main 
'but will be similar to the following:
'
'Content length is 1542
'Content type is text/html; charset=utf-8
'Response stream received.
'<html>
'...
'</html>
'
'
using System;
using System.Net;
using System.Text;
using System.IO;


    public class Test
    {
        // Specify the URL to receive the request.
        public static void
 Main (string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

            // Set some reasonable limits on resources used by this
 request
            request.MaximumAutomaticRedirections = 4;
            request.MaximumResponseHeadersLength = 4;
            // Set credentials to use for this request.
            request.Credentials = CredentialCache.DefaultCredentials;
            HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

            Console.WriteLine ("Content length is {0}", response.ContentLength);
            Console.WriteLine ("Content type is {0}", response.ContentType);
             
            // Get the stream associated with the response.
            Stream receiveStream = response.GetResponseStream ();

            // Pipes the stream to a higher level stream reader with
 the required encoding format. 
            StreamReader readStream = new StreamReader (receiveStream,
 Encoding.UTF8);

            Console.WriteLine ("Response stream received.");
            Console.WriteLine (readStream.ReadToEnd ());
            response.Close ();
            readStream.Close ();
        }
    }

/*
The output from this example will vary depending on the value
 passed into Main 
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/
#using <System.dll>

using namespace System;
using namespace System::Net;
using namespace System::Text;
using namespace System::IO;

// Specify the URL to receive the request.
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   HttpWebRequest^ request = dynamic_cast<HttpWebRequest^>(WebRequest::Create(
 args[ 1 ] ));
   
   // Set some reasonable limits on resources used by this request
   request->MaximumAutomaticRedirections = 4;
   request->MaximumResponseHeadersLength = 4;
   
   // Set credentials to use for this request.
   request->Credentials = CredentialCache::DefaultCredentials;
   HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Content length is {0}", response->ContentLength
 );
   Console::WriteLine( "Content type is {0}", response->ContentType
 );
   
   // Get the stream associated with the response.
   Stream^ receiveStream = response->GetResponseStream();
   
   // Pipes the stream to a higher level stream reader with the required
 encoding format. 
   StreamReader^ readStream = gcnew StreamReader( receiveStream,Encoding::UTF8 );
   Console::WriteLine( "Response stream received." );
   Console::WriteLine( readStream->ReadToEnd() );
   response->Close();
   readStream->Close();
}

/*
The output from this example will vary depending on the value
 passed into Main 
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


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

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

辞書ショートカット

すべての辞書の索引

「HttpWebRequest.GetResponse メソッド」の関連用語


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

   

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



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

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

©2025 GRAS Group, Inc.RSS