使用HttpClient以文件流的方式上传文件(非multipartFormData方式)
@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(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。