HttpWebRequest.GetResponse メソッド
アセンブリ: System (system.dll 内)

Dim instance As HttpWebRequest Dim returnValue As WebResponse returnValue = instance.GetResponse
インターネット リソースからの応答を格納している WebResponse。

例外の種類 | 条件 |
---|---|
InvalidOperationException | ストリームが、既に BeginGetResponse の前回の呼び出しで使用されています。 または |
ProtocolViolationException | Method が GET または HEAD で、ContentLength が 0 以上か、SendChunked が true です。 または KeepAlive は true で、AllowWriteStreamBuffering は false で、ContentLength は -1 で、SendChunked は false で、Method は POST または PUT です。 |
NotSupportedException | 要求のキャッシュ検証コントロールで、この要求の応答がキャッシュから取得できることが示されましたが、この要求にはサーバーに送信するデータが含まれています。データを送信する要求ではキャッシュは使用できません。この例外は、キャッシュ検証コントロールの不適切なカスタム実装を使用した場合に発生することがあります。 |
WebException | または または |

GetResponse メソッドは、インターネット リソースからの応答を格納している WebResponse オブジェクトを返します。実際に返されるインスタンスは HttpWebResponse であり、HTTP 固有のプロパティにアクセスするクラスに型キャストできます。
![]() |
---|

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> */

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


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

- HttpWebRequest.GetResponse メソッドのページへのリンク