本人小白一个,不能保证博客中内容都准确,如果博客中有错误的地方,望各位多多指教,请指正。欢迎找我一起讨论
首先请看获取字节数组byte[]的接口
下面是通过RestTemplate 去访问该接口,然后获取里面的字节数组
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
headers.setContentType(type);
headers.add("Accept", MediaType.APPLICATION_JSON.toString());
JSONObject param = new JSONObject();
param.put("id", id);
HttpEntity<String> formEntity = new HttpEntity<String>(param.toJSONString(), headers);
JSONObject result = restTemplate.postForObject(url, formEntity, JSONObject.class);
byte[] data = result.getObject( "result" , byte[].class );
System.out.println( new String( data, StandardCharsets.UTF_8 ) );