Commit 88611882d4fb710c22d8e2d0bca36a2c144a4c49

Authored by liquanyu
1 parent c58e599e41

update

Showing 1 changed file with 64 additions and 64 deletions

platform-operate-api/src/main/java/com/lyms/platform/operate/web/Test.java View file @ 8861188
1 1 package com.lyms.platform.operate.web;
2 2  
3   -import org.apache.commons.lang.StringUtils;
4   -import org.apache.http.HttpEntity;
5   -import org.apache.http.client.ClientProtocolException;
6   -import org.apache.http.client.config.RequestConfig;
7   -import org.apache.http.client.methods.CloseableHttpResponse;
8   -import org.apache.http.client.methods.HttpPost;
9   -import org.apache.http.entity.ContentType;
10   -import org.apache.http.entity.mime.MultipartEntityBuilder;
11   -import org.apache.http.entity.mime.content.FileBody;
12   -import org.apache.http.entity.mime.content.StringBody;
13   -import org.apache.http.impl.client.CloseableHttpClient;
14   -import org.apache.http.impl.client.HttpClients;
15   -import org.apache.http.util.EntityUtils;
  3 +//import org.apache.commons.lang.StringUtils;
  4 +//import org.apache.http.HttpEntity;
  5 +//import org.apache.http.client.ClientProtocolException;
  6 +//import org.apache.http.client.config.RequestConfig;
  7 +//import org.apache.http.client.methods.CloseableHttpResponse;
  8 +//import org.apache.http.client.methods.HttpPost;
  9 +//import org.apache.http.entity.ContentType;
  10 +//import org.apache.http.entity.mime.MultipartEntityBuilder;
  11 +//import org.apache.http.entity.mime.content.FileBody;
  12 +//import org.apache.http.entity.mime.content.StringBody;
  13 +//import org.apache.http.impl.client.CloseableHttpClient;
  14 +//import org.apache.http.impl.client.HttpClients;
  15 +//import org.apache.http.util.EntityUtils;
  16 +//
  17 +//import java.io.File;
  18 +//import java.io.IOException;
16 19  
17   -import java.io.File;
18   -import java.io.IOException;
19   -
20 20 /**
21 21 * Created by Administrator on 2016/8/22 0022.
22 22 */
23 23 public class Test {
24 24  
25 25 final static long TIME = 1000 * 90;
26   -
27   - public static void main(String[] args) throws Exception {
28   -
29   - File dir = new File("F:\\aa");
30   - File[] files = dir.listFiles();
31   - for (File file : files)
32   - {
33   - upload("https://cert-hengshui-api.healthbaby.com.cn:8787/cp/common/importSignature", file, file.getName());
34   - Thread.sleep(TIME);
35   - }
36   - }
37   -
38   -
39   - public static void upload(String url,File file,String filename) {
40   - CloseableHttpClient httpclient = HttpClients.createDefault();
41   - try {
42   - HttpPost httppost = new HttpPost(url);
43   - RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000000).setSocketTimeout(2000000).build();
44   - httppost.setConfig(requestConfig);
45   - FileBody bin = new FileBody(file);
46   - StringBody comment = new StringBody(filename, ContentType.TEXT_PLAIN);
47   - HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", bin).addPart("filename", comment).build();
48   - httppost.setEntity(reqEntity);
49   - httppost.setHeader("Authorization","12b82e5ef40605bdf213b3c60c4dc69e");
50   - CloseableHttpResponse response = httpclient.execute(httppost);
51   - try {
52   - System.out.println(response.getStatusLine());
53   - HttpEntity resEntity = response.getEntity();
54   - if (resEntity != null) {
55   - String responseEntityStr = EntityUtils.toString(response.getEntity());
56   - System.out.println(file.getName()+"===="+responseEntityStr);
57   - }
58   - EntityUtils.consume(resEntity);
59   - } finally {
60   - response.close();
61   - }
62   - } catch (ClientProtocolException e) {
63   - e.printStackTrace();
64   - } catch (IOException e) {
65   - e.printStackTrace();
66   - } finally {
67   - try {
68   - httpclient.close();
69   - } catch (IOException e) {
70   - e.printStackTrace();
71   - }
72   - }
73   - }
  26 +//
  27 +// public static void main(String[] args) throws Exception {
  28 +//
  29 +// File dir = new File("F:\\aa");
  30 +// File[] files = dir.listFiles();
  31 +// for (File file : files)
  32 +// {
  33 +// upload("https://cert-hengshui-api.healthbaby.com.cn:8787/cp/common/importSignature", file, file.getName());
  34 +// Thread.sleep(TIME);
  35 +// }
  36 +// }
  37 +//
  38 +//
  39 +// public static void upload(String url,File file,String filename) {
  40 +// CloseableHttpClient httpclient = HttpClients.createDefault();
  41 +// try {
  42 +// HttpPost httppost = new HttpPost(url);
  43 +// RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(2000000).setSocketTimeout(2000000).build();
  44 +// httppost.setConfig(requestConfig);
  45 +// FileBody bin = new FileBody(file);
  46 +// StringBody comment = new StringBody(filename, ContentType.TEXT_PLAIN);
  47 +// HttpEntity reqEntity = MultipartEntityBuilder.create().addPart("file", bin).addPart("filename", comment).build();
  48 +// httppost.setEntity(reqEntity);
  49 +// httppost.setHeader("Authorization","12b82e5ef40605bdf213b3c60c4dc69e");
  50 +// CloseableHttpResponse response = httpclient.execute(httppost);
  51 +// try {
  52 +// System.out.println(response.getStatusLine());
  53 +// HttpEntity resEntity = response.getEntity();
  54 +// if (resEntity != null) {
  55 +// String responseEntityStr = EntityUtils.toString(response.getEntity());
  56 +// System.out.println(file.getName()+"===="+responseEntityStr);
  57 +// }
  58 +// EntityUtils.consume(resEntity);
  59 +// } finally {
  60 +// response.close();
  61 +// }
  62 +// } catch (ClientProtocolException e) {
  63 +// e.printStackTrace();
  64 +// } catch (IOException e) {
  65 +// e.printStackTrace();
  66 +// } finally {
  67 +// try {
  68 +// httpclient.close();
  69 +// } catch (IOException e) {
  70 +// e.printStackTrace();
  71 +// }
  72 +// }
  73 +// }
74 74  
75 75 }