| | |
| | | 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;
|
| | |
| | | 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;
|
| | |
|
| | |
| | | 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());
|
| | |
| | | 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();
|
| | |
| | | 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 += "?";
|
| | |
| | |
|
| | | // 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;
|
| | | }
|
| | |
| | |
|
| | | 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);
|
| | |
| | |
|
| | | 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");
|
| | |
| | |
|
| | | 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");
|
| | |
| | | }
|
| | |
|
| | | 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");
|
| | |
| | | @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");
|
| | |
| | |
|
| | | 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()));
|