1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package com.thok.trading.server.util;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.web.client.RestTemplate;
public class RestTemplateUtil {
public static String sendPost(RestTemplate restTemplate,String url,String jsonBody) { HttpHeaders headers = new HttpHeaders(); MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8"); headers.setContentType(type); headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString()); HttpEntity<String> formEntity = new HttpEntity<String>(jsonBody, headers); return restTemplate.postForObject(url, formEntity, String.class); } }
@Autowired private RestTemplate restTemplate;
|