jersey client上传下载文件详解编程语言

jersey client上传文件demo

    File file = new File("/tmp/test.jpg"); 
    System.out.println(file.exists()); 
    FormDataMultiPart part = new FormDataMultiPart(); 
    part.bodyPart(new FileDataBodyPart("file", file)); 
    part.bodyPart(new FormDataBodyPart("myparam", "false")); 
 
    ClientConfig cc = new DefaultClientConfig(); 
    cc.getClasses().add(MultiPartWriter.class); 
    Client writerClient = Client.create(cc); 
    // 处理文件将超时设置为10S 
    writerClient.setConnectTimeout(new Integer(3000)); 
    writerClient.setReadTimeout(new Integer(3000)); 
    try { 
        WebResource resource = writerClient.resource("http://127.0.0.1:8080/rest/upload"); 
        String response = resource.type(MediaType.MULTIPART_FORM_DATA_TYPE).post(String.class, part); 
        System.out.println(response); 
    } finally { 
        writerClient.destroy(); 
    }

jersey client下载文件demo

Client client = Client.create(config); 
 
String sucaisss = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + fuwuAccessToken + "&media_id=" + map.get("MediaId"); 

ClientResponse zongshushuchu
= client.resource(sucaisss).get(ClientResponse.class);

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/19460.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论