public static <T> ResponseEntity<T> fetchTrades(Class<T> resultType, String baseURL, String path, Map<String,String> parms) throws Exception{ return fetchTrades(resultType,baseURL,path,parms,Maps.newHashMap()); } public static <T> ResponseEntity<T> fetchTrades(Class<T> resultType, String baseURL, String path, Map<String,String> parms, Map<String,String> headers) throws Exception{ ResponseEntity<T> responseEntity= null; String uri = buildURI(baseURL,path,parms); HttpHeaders httpHeaders = buildHttpHeader(headers); HttpEntity httpEntity = new HttpEntity(httpHeaders); responseEntity = restTemplate.exchange(uri, HttpMethod.GET, httpEntity,resultType); return responseEntity; } public static String buildURI(String baseURL, String path, Map<String,String> parms) throws Exception{ URIBuilder uriBuilder = new URIBuilder(baseURL).setPath(path); parms.keySet().stream().forEach(key -> uriBuilder.addParameter(key,parms.get(key))); return uriBuilder.build().toString(); } public static HttpHeaders buildHttpHeader(Map<String,String> headers){ HttpHeaders httpHeaders = new HttpHeaders(); headers.keySet().stream().forEach(key -> httpHeaders.add(key,headers.get(key))); return httpHeaders; }
httpclient
最新推荐文章于 2022-06-04 19:44:53 发布