zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    实参和形参
    location对象
    区别 apply,call
    窗体之间的交互(window.opener)
    我的升级脚本总结
    Create elements
    history 对象
    函数参数的属性:callee
    发布app store流程
    【转】如何生成静态页面的五种方案
  • 原文地址:https://www.cnblogs.com/chen-lhx/p/6144716.html
Copyright © 2011-2022 走看看