欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Spring RestTemplate请求第三方接口

程序员文章站 2024-01-28 12:16:58
...
		String encode = URLEncoder.encode(pages);//根据需要转换
		Map<String, Object> param = new HashMap<>();
        param.put("access_token", AccessToken);
        param.put("appname", "douyin");
        param.put("path", encode);
        param.put("width", 430);
        param.put("set_icon", true);
        RestTemplate rest = new RestTemplate();
        InputStream inputStream = null;
        OutputStream outputStream = null;
        File file = null
        String url = "https://developer.toutiao.com/api/apps/qrcode";
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        HttpEntity requestEntity = new HttpEntity(param, headers);
        ResponseEntity<byte[]> entity =
        rest.exchange(url, HttpMethod.POST, requestEntity, byte[].class, new Object[0]);
        if (entity.getStatusCodeValue() != 200) {
            return "获取失败";
        }
        byte[] result = entity.getBody();
相关标签: java