HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("type", "type"); map.add("code", "code"); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(map, headers); String url = "http://......"; ResponseEntity<byte[]> entity = new TestRestTemplate() .postForEntity(url, request, byte[].class); assertEquals(HttpStatus.OK, entity.getStatusCode()); byte[] body = entity.getBody(); log.info("获取响应body:" + body); String bodyStr = new String(body,"utf-8"); log.info("获取bodyStr:" + bodyStr);
标签:body,map,调用,String,外部,接口,entity,bodyStr,new From: https://www.cnblogs.com/tsvv-plus/p/17083108.html