https://sm.ms图库上传工具类

    public static void main(String[] args) throws Exception {
        //调用smms图床上传图片
        String urls = "https://sm.ms/api/v2/upload";
        String filePath = "/Users/liaochongzhou/Documents/lcz/zhou/xm/personal-blog/image/2.png";
        //调用post请求上传图片
        String result = HttpRequest.post(urls)
                .header("Authorization", "")
                .header("User-Agent", "Mozilla/5.0")
                .header("Content-Type", "application/x-www-form-urlencoded")
                .form("smfile", new File(filePath))
                .timeout(20000)
                .execute().body();
        Map map = JSON.parseObject(result, Map.class);
        if ("true".equals(map.get("success"))) {
            JSONObject data = (JSONObject) map.get("data");
            String url = (String) data.get("url");
            System.out.println(url);
        } else {
            System.out.println(map.get("images"));
        }
    }
    

你可能感兴趣的:(java,servlet,jvm)