posts - 496,comments - 227,trackbacks - 0
    public void test() throws IOException {
        MockMultipartFile file = new MockMultipartFile("历史.bmp",
                                                       "历史.bmp",
                                                       "image/bmp",
                                                       FileUtils.openInputStream(new File("C:\\Users\\simone\\Pictures\\历史.bmp")));
        String fileName = file.getOriginalFilename();
        
        HttpPost httpPost = new HttpPost("http://xxxxxxxx/defupload");
        
        StringBody token = new StringBody("b27322a42a913b191398035f530c4155", ContentType.TEXT_PLAIN);
        ByteArrayBody byteArrayBody = new ByteArrayBody(file.getBytes(), fileName);
        HttpEntity reqEntity = MultipartEntityBuilder.create()
                                                     .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
                                                     .addPart("token", token)
                                                     .addPart("file", byteArrayBody)
                                                     .setCharset(CharsetUtils.get("UTF-8"))
                                                     .build();
        httpPost.setEntity(reqEntity);
        CloseableHttpClient httpClient = HttpClients.custom().setProxy(new HttpHost("127.0.0.1", 8888)).build();
        
        CloseableHttpResponse response = httpClient.execute(httpPost);
        
        EntityUtils.toString(response.getEntity());
        
        response.close();
    }
posted on 2015-11-17 16:44 SIMONE 阅读(343) 评论(0)  编辑  收藏 所属分类: JAVA

只有注册用户登录后才能发表评论。


网站导航: