这里有一个接口返回的是JSON对象, 请求一个图片下载成byte[] @PostMapping(value = "/testjxd") public JSONObject test(@RequestBody JSONObject value) { RestTemplate restTemplate = new RestTemplate(); byte[] rest =restTemplate.getForObject("http://wt-r2.oss-cn-beijing.aliyuncs.com/wtWordPhoto/GoogleTest.jpg",byte[].class); return (JSONObject)JSON.toJSON(Result.success(rest)); }
请求一个接口
public static void main(String[] args) { RestTemplate restTemplate = new RestTemplate(); JSONObject send=new JSONObject(); send.put("name","jxd"); JSONObject jsonObject =restTemplate.postForObject("http://......testjxd",send,JSONObject.class); System.out.println(jsonObject.getString("data")); byte[] bytes=base64String2ByteFun(jsonObject.getString("data"));//转成base64图片用 System.out.println(bytes); }
看到了吗很方便几行代码就可以完成