パッケージ org.springframework.http
クラス HttpEntity<T>
java.lang.ObjectSE
org.springframework.http.HttpEntity<T>
- 型パラメーター:
T- ボディ型
- 既知の直属サブクラス
RequestEntity,ResponseEntity
ヘッダーと本文で構成される HTTP リクエストまたはレスポンスエンティティを表します。
多くの場合、次のように RestTemplate と組み合わせて使用されます。
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
HttpEntity<String> entity = new HttpEntity<>("Hello World", headers);
URI location = template.postForLocation("https://example.com", entity);
または
HttpEntity<String> entity = template.getForEntity("https://example.com", String.class);
String body = entity.getBody();
MediaType contentType = entity.getHeaders().getContentType();
@Controller メソッドからの戻り値として、Spring MVC で使用することもできます。
@GetMapping("/handle")
public HttpEntity<String> handle() {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("MyResponseHeader", "MyValue");
return new HttpEntity<>("Hello World", responseHeaders);
}
- 導入:
- 3.0.2
- 作成者:
- Arjen Poutsma, Juergen Hoeller
- 関連事項:
フィールドのサマリー
フィールドコンストラクターの概要
コンストラクター修飾子コンストラクター説明protected新しい空のHttpEntityを作成します。HttpEntity(MultiValueMap<StringSE, StringSE> headers) 与えられたヘッダーを持ち、本文を持たない新しいHttpEntityを作成します。HttpEntity(T body) 指定された本文を使用してヘッダーなしで新しいHttpEntityを作成します。HttpEntity(T body, MultiValueMap<StringSE, StringSE> headers) 指定されたボディとヘッダーで新しいHttpEntityを作成します。メソッドのサマリー
フィールドの詳細
EMPTY
本文またはヘッダーのない空のHttpEntity。
コンストラクターの詳細
HttpEntity
protected HttpEntity()新しい空のHttpEntityを作成します。HttpEntity
指定された本文を使用してヘッダーなしで新しいHttpEntityを作成します。- パラメーター:
body- エンティティ本体
HttpEntity
与えられたヘッダーを持ち、本文を持たない新しいHttpEntityを作成します。- パラメーター:
headers- エンティティヘッダー
HttpEntity
指定されたボディとヘッダーで新しいHttpEntityを作成します。- パラメーター:
body- エンティティ本体headers- エンティティヘッダー
メソッドの詳細