码迷,mamicode.com
首页 > Web开发 > 详细

使用HttpClient以文件流的方式上传文件(非multipartFormData方式)

时间:2015-03-06 00:55:39      阅读:622      评论:0      收藏:0      [点我收藏+]

标签:

@Test
    public void testAdd() throws IOException {
        HttpPost post = new HttpPost("http://localhost:8182/api/media/add?app=test&access_token=1234&fileName=测试一下.jpg&ContentType=image/jpeg");
        HttpEntity entity = new FileEntity(new File("C:\\Users\\Administrator\\Desktop\\C360_2013-06-24-08-44-38-027.jpg"));
        post.setEntity(entity);
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = httpClient.execute(post);
        System.out.println(response.getStatusLine().getStatusCode());
        response.close();
        httpClient.close();
    }

 

使用HttpClient以文件流的方式上传文件(非multipartFormData方式)

标签:

原文地址:http://www.cnblogs.com/jiaoyiping/p/4317053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!