admin
2019-02-22 e358583d644fa39fc1e93b14b3cafff3644980e4
fanli-facade-system/src/main/java/org/fanli/facade/system/util/taobao/TaoBaoHttpUtil.java
@@ -6,7 +6,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
@@ -30,9 +29,6 @@
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import com.yeshi.fanli.entity.address.Address;
import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
import net.sf.json.JSONArray;
@@ -104,12 +100,6 @@
   public static String get(String url, boolean isProxy) {
      HttpClient client = new HttpClient();
      GetMethod method = new GetMethod(url);
      if (isProxy) {
         Address address = ProxyUtil.getAddressProxy();
         if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
         }
      }
      try {
         client.executeMethod(method);
         return convertInputStreamToString(method.getResponseBodyAsStream());
@@ -124,12 +114,6 @@
   public static String getAsString(String url, boolean isProxy) {
      HttpClient client = new HttpClient();
      GetMethod method = new GetMethod(url);
      if (isProxy) {
         Address address = ProxyUtil.getAddressProxy();
         if (address != null) {
            client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
         }
      }
      try {
         client.executeMethod(method);
         String response = method.getResponseBodyAsString();
@@ -143,59 +127,8 @@
      return "";
   }
   public static String tbGet(String url, Map<String, String> params, String tbAccount) {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      // if(address != null){
      // client.getHostConfiguration().setProxy(address.getIp(),
      // address.getPort());
      // }
      Iterator<String> keys = params.keySet().iterator();
      url += "?";
      while (keys.hasNext()) {
         String key = keys.next();
         try {
            url += String.format("%s=%s&", key, URLEncoder.encode(params.get(key), "UTF-8"));
         } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
         }
      }
      GetMethod method = new GetMethod(url);
      try {
         method.setRequestHeader("User-Agent",
               "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
         method.setRequestHeader("Upgrade-Insecure-Requests", "1");
         method.setRequestHeader("Accept",
               "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
         method.setRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
         method.setRequestHeader("Cache-Control", "max-age=0");
         String taoBaoCookie = TaoBaoOrderUtil.getTaoBaoCookie(tbAccount);
         method.setRequestHeader("cookie", taoBaoCookie);
         // HttpConnectionManagerParams params2 = new
         // HttpConnectionManagerParams();
         // params2.setConnectionTimeout(3500);
         // client.getHttpConnectionManager().setParams(params2);
         client.executeMethod(method);
         // InputStream inputStream = method.getResponseBodyAsStream();
         // String result = convertInputStreamToString(inputStream);
         return method.getResponseBodyAsString();// convertInputStreamToString(method.getResponseBodyAsStream());
      } catch (Exception e) {
         try {
            address = ProxyUtil.getAddressProxy();
            if (address != null) {
               client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
            }
            client.executeMethod(method);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      return "";
   }
   public static String get(String url, Map<String, String> params, boolean proxy) {
      HttpClient client = new HttpClient();
      // client.getHostConfiguration().setProxy("192.168.1.122", 8888);
      try {
         Iterator<String> keys = params.keySet().iterator();
         url += "?";
@@ -277,8 +210,8 @@
      // result = get("http://118.178.179.189/taoke/", params, false);
      // if (StringUtil.isNullOrEmpty(result))
      //https://eco.taobao.com/router/rest
      //http://gw.api.taobao.com/router/rest
      // https://eco.taobao.com/router/rest
      // http://gw.api.taobao.com/router/rest
      String result = get("https://eco.taobao.com/router/rest", params, false);
      return result;
   }
@@ -291,10 +224,6 @@
   public static String get(String url, String charset) {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      GetMethod method = new GetMethod(url);
      try {
         client.executeMethod(method);
@@ -331,10 +260,6 @@
   public static InputStream getImage(String url) {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      GetMethod method = new GetMethod(url);
      try {
         method.setRequestHeader("Content-Type", "image/jpeg");
@@ -350,10 +275,6 @@
   public static String post(String url) {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      PostMethod method = new PostMethod(url);
      method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
      method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
@@ -380,10 +301,6 @@
      }
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      PostMethod method = new PostMethod(url);
      method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
      method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
@@ -444,10 +361,6 @@
   @SuppressWarnings("deprecation")
   public static String post(String url, String entity) {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      PostMethod method = new PostMethod(url);
      method.addRequestHeader("Content-Type", "text/html;charset=UTF-8");
      method.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
@@ -465,17 +378,7 @@
   public static String postInputStream(String url, File file) throws FileNotFoundException {
      HttpClient client = new HttpClient();
      Address address = ProxyUtil.getAddressProxy();
      if (address != null) {
         client.getHostConfiguration().setProxy(address.getIp(), address.getPort());
      }
      PostMethod postMethod = new PostMethod(url);
      /*
       * postMethod.addRequestHeader("Content-Type",
       * "text/html;charset=UTF-8");
       * postMethod.setRequestHeader("Content-Type",
       * "text/html;charset=UTF-8");
       */
      Part[] parts = { new StringPart("filename", file.getName()), new StringPart("filelength", file.length() + ""),
            new StringPart("content-type", "image/jpg"), new FilePart("file", file) };
      postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));