HttpResponseMessage クラス
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
ステータス コードとデータを含む HTTP 応答メッセージを表します。
public ref class HttpResponseMessage : IDisposable
public class HttpResponseMessage : IDisposable
type HttpResponseMessage = class
interface IDisposable
Public Class HttpResponseMessage
Implements IDisposable
- 継承
-
HttpResponseMessage
- 実装
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
static readonly HttpClient client = new HttpClient();
static async Task Main()
{
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
{
using HttpResponseMessage response = await client.GetAsync("http://www.contoso.com/");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
// Above three lines can be replaced with new helper method below
// string responseBody = await client.GetStringAsync(uri);
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
open System.Net.Http
// HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
let client = new HttpClient()
let main =
task {
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
use! response = client.GetAsync "http://www.contoso.com/"
response.EnsureSuccessStatusCode() |> ignore
let! responseBody = response.Content.ReadAsStringAsync()
// Above three lines can be replaced with new helper method below
// let! responseBody = client.GetStringAsync uri
printfn $"{responseBody}"
with
| :? HttpRequestException as e ->
printfn "\nException Caught!"
printfn $"Message :{e.Message} "
}
main.Wait()
' HttpClient is intended to be instantiated once per application, rather than per-use. See Remarks.
Shared ReadOnly client As HttpClient = New HttpClient()
Private Shared Async Function Main() As Task
' Call asynchronous network methods in a try/catch block to handle exceptions.
Try
Using response As HttpResponseMessage = Await client.GetAsync("http://www.contoso.com/")
response.EnsureSuccessStatusCode()
Dim responseBody As String = Await response.Content.ReadAsStringAsync()
' Above three lines can be replaced with new helper method below
' Dim responseBody As String = Await client.GetStringAsync(uri)
Console.WriteLine(responseBody)
End Using
Catch e As HttpRequestException
Console.WriteLine(Environment.NewLine & "Exception Caught!")
Console.WriteLine("Message :{0} ", e.Message)
End Try
End Function
前のコード例では、エントリ ポイントを async Task Main()
使用しています。 この機能には C# 7.1 以降が必要です。
を取得 HttpResponseMessage する一般的な方法は、いずれかの HttpClient.SendAsync(HttpRequestMessage) メソッドから行います。
Http |
HttpResponseMessage クラスの新しいインスタンスを初期化します。 |
Http |
特定の StatusCode を使用して、HttpResponseMessage クラスの新しいインスタンスを初期化します。 |
Content |
HTTP 応答メッセージの内容を取得または設定します。 |
Headers |
HTTP 応答ヘッダーのコレクションを取得します。 |
Is |
HTTP 応答が成功したかどうかを示す値を取得します。 |
Reason |
ステータス コードと共にサーバーが通常送信する理由語句を取得または設定します。 |
Request |
この応答メッセージを引き起こした要求メッセージを取得または設定します。 |
Status |
HTTP 応答のステータス コードを取得または設定します。 |
Trailing |
HTTP 応答に含まれている末尾のヘッダーのコレクションを取得します。 |
Version |
HTTP メッセージ バージョンを取得または設定します。 |
Dispose() |
HttpResponseMessage が使用しているアンマネージ リソースを解放し、アンマネージ リソースを破棄します。 |
Dispose(Boolean) |
HttpResponseMessage が使用しているアンマネージド リソースを解放します。オプションとして、マネージド リソースを破棄することもできます。 |
Ensure |
HTTP 応答の IsSuccessStatusCode プロパティが |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
Get |
既定のハッシュ関数として機能します。 (継承元 Object) |
Get |
現在のインスタンスの Type を取得します。 (継承元 Object) |
Memberwise |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
To |
現在のオブジェクトを表す文字列を返します。 |
To |
Message インスタンスから HttpResponseMessage インスタンスを作成します。 |
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。