定制化开发这里有一个接口返回的是JSON对象, 请求一个图片下载成byte[ ]
@PostMapping(value = “/test”) public test(@RequestBody
JSONObject value) {RestTemplate restTemplate = new RestTemplate();byte[] rest =restTemplate.getForObject("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1608292416081&di=596e6e1353e265b0a2998918cd61888f&imgtype=0&src=http%3A%2F%2Fa0.att.hudong.com%2F52%2F62%2F31300542679117141195629117826.jpg",byte[].class);return (JSONObject)JSON.toJSON(Result.success(rest)); }
- 1
- 2
- 3
请求一个接口
public static void main(String[] args) {
restTemplate = new RestTemplate();
JSONObject send=new JSONObject();
send.put(“name”,“xx”);
JSONObject jsonObject =restTemplate.postForObject(“http://…test”,send,JSONObject.class);
System.out.println(jsonObject.getString(“data”));
byte[] bytes=base64String2ByteFun(jsonObject.getString(“data”));//转成base64图片用
System.out.println(bytes); }
很少代码就可以完成,测试有效
如果对你有帮助,请一定要帮忙点赞好评,给予创作的动力…