constructor
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
ResponseEntity ile kullanılabilir. Şöyle yaparız.
Örnek
RestTemplate ile kullanılabilir. Şöyle yaparız.
Şöyle yaparız.
HttpHeaders headers = new HttpHeaders();Şöyle yaparız.
headers.add("content-Type", MediaType.IMAGE_JPEG_VALUE);Şöyle yaparız.
String filename= ...;
String contentType = ...;
Map<String, String> map = new HashMap<>();
map.put("Content-disposition", "attachment; filename=\"" + filename + "\"");
map.put("Content-Type", contentType);HttpHeaders headers = new HttpHeaders();
headers.setAll(map);setContentType metodu
Örnek
Şöyle yaparız.headers.setContentType(MediaType.MULTIPART_FORM_DATA);Diğer
ÖrnekResponseEntity ile kullanılabilir. Şöyle yaparız.
return ResponseEntity.status(...).headers(headers).body(...);Örnek
Bellekte yaratılan CSV içeri dönmek için şöyle yaparız
@GetMapping(value = "/exportCSV", produces = "text/csv")
public ResponseEntity<Resource> exportCSV() {
  ByteArrayInputStream byteArrayOutputStream;
  ...
  InputStreamResource fileInputStream = new InputStreamResource(byteArrayOutputStream);
  String csvFileName = "people.csv";
  // setting HTTP headers
  HttpHeaders headers = new HttpHeaders();
  headers.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + csvFileName);
  // defining the custom Content-Type
  headers.set(HttpHeaders.CONTENT_TYPE, "text/csv");
  return new ResponseEntity<>(
    fileInputStream,
    headers,
    HttpStatus.OK
  );
}RestTemplate ile kullanılabilir. Şöyle yaparız.
HttpHeaders headers = ...
MultiValueMap<String, Object> body = ...
HttpEntity<MultiValueMap<String,Object>> requestEntity = new HttpEntity<>(body, headers);
String serverUrl = "https://api.com/api";
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate
  .postForEntity(serverUrl, requestEntity, String.class); 
Hiç yorum yok:
Yorum Gönder