posts - 495,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 閱讀(627) 評論(0)  編輯  收藏 所屬分類: JAVA
          主站蜘蛛池模板: 民勤县| 灌南县| SHOW| 泸州市| 定陶县| 昌乐县| 广汉市| 绥阳县| 大丰市| 天等县| 九龙坡区| 阳泉市| 奉贤区| 托克逊县| 淅川县| 驻马店市| 土默特右旗| 绵竹市| 射阳县| 新竹县| 石城县| 堆龙德庆县| 苍梧县| 五莲县| 原平市| 裕民县| 陕西省| 张家口市| 涞水县| 广州市| 浑源县| 马鞍山市| 类乌齐县| 黔南| 开封县| 西峡县| 博湖县| 甘南县| 上栗县| 连云港市| 瑞金市|