1

Postman request

https://i.sstatic.net/ILbhN.png]

As mentioned in image I would like to send content-type as application/json for a particular part of a multipart request in springboot application.

1 Answer 1

2

use MultipartBodyBuilder to build your request.

HttpHeaders headers = new HttpHeaders();

headers.setContentType(MediaType.MULTIPART_FORM_DATA);

headers.add("add custome header", "header value");

MultipartBodyBuilder builder = new MultipartBodyBuilder();

builder.part("json_part", "").header("Content-Type", "application/json");

MultiValueMap<String, HttpEntity<?>> body = builder.build();

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity(body, 
headers);

RestTemplate restTemplate = new RestTemplateBuilder().build();

ResponseEntity<String> postResponse = restTemplate
    .postForEntity("yoururl", requestEntity, String.class);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.