123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- package cn.com.ctop.common.utils;
- import com.alibaba.fastjson.JSONObject;
- import com.google.gson.Gson;
- import org.apache.fontbox.ttf.CmapSubtable;
- import org.apache.fontbox.ttf.GlyphData;
- import org.apache.fontbox.ttf.TTFParser;
- import org.apache.fontbox.ttf.TrueTypeFont;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.HttpStatus;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.CookieStore;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.config.CookieSpecs;
- import org.apache.http.client.config.RequestConfig;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
- import org.apache.http.conn.ssl.TrustStrategy;
- import org.apache.http.cookie.Cookie;
- import org.apache.http.entity.StringEntity;
- import org.apache.http.impl.client.BasicCookieStore;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.message.BasicNameValuePair;
- import org.apache.http.ssl.SSLContextBuilder;
- import org.apache.http.util.EntityUtils;
- import org.eclipse.jetty.util.UrlEncoded;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import javax.net.ssl.SSLContext;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import java.net.URLEncoder;
- import java.nio.charset.Charset;
- import java.security.cert.CertificateException;
- import java.security.cert.X509Certificate;
- import java.util.*;
- public class HttpUtils {
- private static final Logger logger = LoggerFactory.getLogger(HttpUtils.class);
- public static CookieStore cookieStore = new BasicCookieStore();
- //.setProxy(new HttpHost("106.125.239.179", 4245))
- public static Map<String, Map<String, String>> fontsMap = new HashMap<String, Map<String, String>>();
- public static String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36";
- public static CloseableHttpClient createSSLClientDefault() {
- try {
- SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
- //信任所有证书
- public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
- return true;
- }
- }).build();
- RequestConfig globalConfig = RequestConfig.custom().setConnectTimeout(30000).setSocketTimeout(30000).setCookieSpec(CookieSpecs.STANDARD).build();
- SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory(sslContext);
- return HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultRequestConfig(globalConfig).setConnectionReuseStrategy((response, context) -> false).setSSLSocketFactory(sslFactory).build();
- } catch (Exception e) {
- logger.error("处理Https证书异常", e);
- }
- return HttpClients.createDefault();
- }
- public static String httpPostParamRequest(String url, Map<String, Object> param, Map<String, String> headers) {
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.setHeader("User-Agent", USER_AGENT);
- List<Cookie> list = cookieStore.getCookies();
- // for (Cookie ck : list) {
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- // System.out.println("-------------------------------------");
- for (String key : headers.keySet()) {
- httppost.setHeader(key, headers.get(key));
- }
- List<NameValuePair> paramList = new ArrayList<NameValuePair>();
- for (String key : param.keySet()) {
- BasicNameValuePair basicNameValuePair = new BasicNameValuePair(key, String.valueOf(param.get(key)));
- paramList.add(basicNameValuePair);
- }
- // 第二步:我们发现Entity是一个接口,所以只能找实现类,发现实现类又需要一个集合,集合的泛型是NameValuePair类型
- UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramList);
- // 第一步:通过setEntity 将我们的entity对象传递过去
- httppost.setEntity(formEntity);
- //httppost.setHeader("Content-Type", "application/json");
- // httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
- String newUrl = response.getFirstHeader("Location").getValue();
- return httpPostParamRequest(newUrl, param, headers);
- } else if (statusCode == HttpStatus.SC_OK) {
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- return strReturn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpPostRequest(String url, Map<String, Object> param, Map<String, String> headers) {
- // HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.setHeader("User-Agent", USER_AGENT);
- httppost.addHeader("Content-Type", "application/json");
- List<Cookie> list = cookieStore.getCookies();
- // for (Cookie ck : list) {
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- for (String key : headers.keySet()) {
- httppost.setHeader(key, headers.get(key));
- }
- //httppost.setHeader("Content-Type", "application/json");
- httppost.setEntity(new StringEntity(new Gson().toJson(param), Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
- String newUrl = response.getFirstHeader("Location").getValue();
- return httpPostRequest(newUrl, param, headers);
- } else if (statusCode == HttpStatus.SC_OK) {
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- return strReturn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpPostRequestTest(String url, String body, Map<String, String> headers) {
- // HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.setHeader("User-Agent", USER_AGENT);
- httppost.addHeader("Content-Type", "application/json");
- List<Cookie> list = cookieStore.getCookies();
- for (Cookie ck : list) {
- System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- }
- for (String key : headers.keySet()) {
- httppost.setHeader(key, headers.get(key));
- }
- //httppost.setHeader("Content-Type", "application/json");
- httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
- String newUrl = response.getFirstHeader("Location").getValue();
- return httpPostRequestTest(newUrl, body, headers);
- } else if (statusCode == HttpStatus.SC_OK) {
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- return strReturn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String kuaiShouhttpPostRequest(String url, String body, Map<String, String> headers) {
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- if (!Check.isNullMap(headers)) {
- for (String key : headers.keySet()) {
- httppost.setHeader(key, headers.get(key));
- }
- }
- httppost.setHeader("User-Agent", USER_AGENT);
- if (!Check.isNull(body)) {
- httppost.setEntity(new StringEntity(body, Charset.forName("UTF-8")));
- }
- HttpEntity respentity;
- System.err.println(httppost);
- HttpResponse response = httpClient.execute(httppost);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_OK) {
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- return strReturn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpPostRequest(String url, JSONObject params, Map<String, String> headers) {
- // HttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.setHeader("User-Agent", USER_AGENT);
- httppost.addHeader("Content-Type", "application/json");
- List<Cookie> list = cookieStore.getCookies();
- // for (Cookie ck : list) {
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- for (String key : headers.keySet()) {
- httppost.setHeader(key, headers.get(key));
- }
- //httppost.setHeader("Content-Type", "application/json");
- httppost.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
- String newUrl = response.getFirstHeader("Location").getValue();
- return httpPostRequest(newUrl, params, headers);
- } else if (statusCode == HttpStatus.SC_OK) {
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- return strReturn;
- }
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpGetRequest(String url) {
- HttpClient httpClient = createSSLClientDefault();
- HttpResponse response = null;
- HttpGet httpGet = new HttpGet(url);
- // httpPost.setHeader("Content-Type", "application/json");
- String result = null;
- try {
- httpGet.setHeader("User-Agent", USER_AGENT);
- List<Cookie> list2 = cookieStore.getCookies();
- // for (Cookie ck : list2) {
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- response = httpClient.execute(httpGet);
- List<Cookie> list = cookieStore.getCookies();
- // for (Cookie ck : list) {
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- int statusCode = response.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
- String newUrl = response.getFirstHeader("Location").getValue();
- return httpGetRequest(newUrl);
- } else if (statusCode == HttpStatus.SC_OK) {
- BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- String line = null;
- StringBuilder builder = new StringBuilder();
- while ((line = reader.readLine()) != null) {
- builder.append(line);
- }
- result = builder.toString();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
- public static String httpRequest(String url, String strParams) throws Exception {
- // HttpClient httpclient = HttpClientBuilder.create().build();
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.addHeader("Content-Type", "application/json");
- httppost.setEntity(new StringEntity(strParams, Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- int code = response.getStatusLine().getStatusCode();
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpRequest(String url, CookieStore cookies, Map<String, String> parameterMap) throws Exception {
- // HttpClient httpclient = getHttpclient();
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpPost httppost = new HttpPost(url);
- httppost.setHeader("Content-Type", "application/json");
- UrlEncodedFormEntity postEntity = new UrlEncodedFormEntity(
- getParam(parameterMap), "UTF-8");
- httppost.setEntity(postEntity);
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httppost);
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static List<NameValuePair> getParam(Map parameterMap) {
- List<NameValuePair> param = new ArrayList<NameValuePair>();
- Iterator it = parameterMap.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry parmEntry = (Map.Entry) it.next();
- param.add(new BasicNameValuePair((String) parmEntry.getKey(),
- (String) parmEntry.getValue()));
- }
- return param;
- }
- public static HttpClient getHttpclient() {
- RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(180000).setConnectTimeout(30000)
- .setConnectionRequestTimeout(30000).setStaleConnectionCheckEnabled(true).build();
- CloseableHttpClient httpclient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
- return httpclient;
- }
- public static String callingGraph(String url, String json) {
- HttpClient httpClient = createSSLClientDefault();
- HttpResponse response = null;
- HttpPost httpPost = new HttpPost(url);
- List<Cookie> list = cookieStore.getCookies();
- // cookieStore.clear();
- // for (Cookie ck : list) {
- //
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- // System.out.println("-------------------------------------");
- httpPost.setHeader("Content-Type", "application/json");
- String result = null;
- try {
- StringEntity entity = new StringEntity(json, "utf-8");
- httpPost.setHeader("User-Agent", USER_AGENT);
- httpPost.setEntity(entity);
- response = httpClient.execute(httpPost);
- BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- String line = null;
- StringBuilder builder = new StringBuilder();
- while ((line = reader.readLine()) != null) {
- builder.append(line);
- }
- // for (Cookie ck : list) {
- //
- // System.out.println(ck.getName() + "=" + ck.getValue() + "," + ck.getDomain());
- // }
- result = builder.toString();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
- public static Map<String, Integer> kuaishouNumberMap;
- public static Integer getKuaishouNumber(String key) {
- if (kuaishouNumberMap == null) {
- kuaishouNumberMap = new HashMap<>();
- // kuaishouNumberMap.put("32.0#-6.0#526.0#729.0",0);//735
- // kuaishouNumberMap.put("98.0#13.0#363.0#726.0",1);//713
- // kuaishouNumberMap.put("32.0#13.0#527.0#732.0",2);//719
- // kuaishouNumberMap.put("25.0#-6.0#525.0#730.0",3);//736
- // kuaishouNumberMap.put("26.0#13.0#536.0#731.0",4);//718
- // kuaishouNumberMap.put("33.0#-5.0#526.0#717.0",5);//722
- // kuaishouNumberMap.put("39.0#-5.0#530.0#732.0",6);//737
- // kuaishouNumberMap.put("38.0#13.0#536.0#717.0",7);//704
- // kuaishouNumberMap.put("33.0#-7.0#525.0#731.0",8);//738
- // kuaishouNumberMap.put("37.0#-7.0#521.0#730.0",9);//737
- kuaishouNumberMap.put("494.0#735.0", 0);
- kuaishouNumberMap.put("265.0#713.0", 1);
- kuaishouNumberMap.put("495.0#719.0", 2);
- kuaishouNumberMap.put("500.0#736.0", 3);
- kuaishouNumberMap.put("510.0#718.0", 4);
- kuaishouNumberMap.put("493.0#722.0", 5);
- kuaishouNumberMap.put("491.0#737.0", 6);
- kuaishouNumberMap.put("498.0#704.0", 7);
- kuaishouNumberMap.put("492.0#738.0", 8);
- kuaishouNumberMap.put("484.0#737.0", 9);
- }
- return kuaishouNumberMap.get(key);
- }
- public static void kuaishouTtf(String ttfName) {
- try {
- URL url = new URL("https://static.yximgs.com/udata/pkg/kuaishou-front-end-live/" + ttfName); // 创建URL
- URLConnection urlconn = url.openConnection();
- TTFParser ttfParser = new TTFParser();
- TrueTypeFont ttf = ttfParser.parse(urlconn.getInputStream());
- // System.out.println(new Gson().toJson(ttf.getGlyph().getGlyphs()));
- GlyphData[] datas = ttf.getGlyph().getGlyphs();
- CmapSubtable[] tables = ttf.getCmap().getCmaps();
- Gson gson = new Gson();
- // System.out.println(gson.toJson(tables));
- CmapSubtable table = tables[0];
- Map<String, Integer> numberMap = new HashMap<String, Integer>();
- Map<String, String> fontMap = new HashMap<String, String>();
- for (int i = 0; i <= 13; i++) {
- GlyphData data = datas[i];
- if (data != null) {
- // System.out.println("getBoundingBox" + data.getBoundingBox());
- float fx = data.getBoundingBox().getLowerLeftX();
- float fy = data.getBoundingBox().getLowerLeftY();
- float rx = data.getBoundingBox().getUpperRightX();
- float ry = data.getBoundingBox().getUpperRightY();
- Integer num = getKuaishouNumber(String.valueOf(rx - fx) + "#" + String.valueOf(ry - fy));
- // if (num != null) {
- // System.out.println(num);
- // }
- fontMap.put(String.valueOf((char) table.getCharCodes(i).get(0).intValue()), String.valueOf(num));
- }
- }
- // System.out.println(new Gson().toJson(fontMap));
- fontsMap.put(ttfName, fontMap);
- for (GlyphData data : datas) {
- if (data != null) {
- // System.out.println("getBoundingBox" + data.getBoundingBox());
- float fx = data.getBoundingBox().getLowerLeftX();
- float fy = data.getBoundingBox().getLowerLeftY();
- float rx = data.getBoundingBox().getUpperRightX();
- float ry = data.getBoundingBox().getUpperRightY();
- Integer num = getKuaishouNumber(String.valueOf(fx) + "#" + String.valueOf(fy) + "#" + String.valueOf(rx) + "#" + String.valueOf(ry));
- // System.out.println(num);
- }
- }
- // System.out.println(new Gson().toJson(numberMap));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static String mapParamsSortToStringBySeperator(TreeMap<String, Object> treeMap, String seperator) {
- String result = "";
- if (null != treeMap && !treeMap.isEmpty()) {
- for (Map.Entry<String, Object> entry : treeMap.entrySet()) {
- String key = entry.getKey();
- String value = UrlEncoded.encodeString((String) entry.getValue());
- result += (key + "=" + value + seperator);
- }
- if (result.length() > 0) {
- result = result.substring(0, result.length() - seperator.length());
- }
- }
- return result;
- }
- public static String httpGetRequest(String url, Map<String, String> headers, TreeMap<String, Object> params) {
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- String uri = url + "?" + mapParamsSortToStringBySeperator(params, "&");
- HttpGet httpGet = new HttpGet(uri);
- if (headers != null) {
- Iterator<String> keyIter = headers.keySet().iterator();
- while (keyIter.hasNext()) {
- String curKey = keyIter.next();
- if (curKey != null && headers.get(curKey) != null) {
- httpGet.addHeader(curKey, headers.get(curKey));
- }
- }
- }
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httpGet);
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpGetRequest(String url, Map<String, String> headers, JSONObject params) {
- HttpClient httpClient = createSSLClientDefault();
- String strReturn = "";
- try {
- HttpGetWithBodyEntity httpGet = new HttpGetWithBodyEntity(url);
- if (headers != null) {
- Iterator<String> keyIter = headers.keySet().iterator();
- while (keyIter.hasNext()) {
- String curKey = keyIter.next();
- if (curKey != null && headers.get(curKey) != null) {
- httpGet.addHeader(curKey, headers.get(curKey));
- }
- }
- }
- httpGet.setEntity(new StringEntity(params.toJSONString(), Charset.forName("UTF-8")));
- HttpEntity respentity;
- HttpResponse response = httpClient.execute(httpGet);
- respentity = response.getEntity();
- strReturn = EntityUtils.toString(respentity);
- } catch (Exception e) {
- e.printStackTrace();
- logger.error(e.getMessage());
- }
- return strReturn;
- }
- public static String httpGet(String url, Map<String, Object> paramsMap, Map<String, String> headers) {
- String result = null;
- try {
- // CloseableHttpClient httpClient = HttpClients.createDefault();
- //创建参数列表
- HttpClient httpclient = getHttpclient();
- StringBuilder postBody = null;
- if (!Check.isNull(paramsMap)) {
- postBody = new StringBuilder();
- for (Map.Entry<String, Object> entry : paramsMap.entrySet()) {
- if (entry.getValue() == null) {
- continue;
- }
- postBody.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(),
- "utf-8")).append("&");
- }
- if (!paramsMap.isEmpty()) {
- postBody.deleteCharAt(postBody.length() - 1);
- }
- }
- String urlStr;
- if (!Check.isNull(postBody)) {
- urlStr = url + "?" + postBody;
- } else {
- urlStr = url;
- }
- HttpGet httpget = new HttpGet(urlStr);
- httpget.setHeader("User-Agent", USER_AGENT);
- if (!Check.isNullMap(headers)) {
- for (String key : headers.keySet()) {
- httpget.setHeader(key, headers.get(key));
- }
- }
- HttpEntity respEntity;
- System.err.println(httpget);
- HttpResponse response = httpclient.execute(httpget);
- respEntity = response.getEntity();
- result = EntityUtils.toString(respEntity);
- } catch (Exception e) {
- logger.error("http get请求异常");
- e.printStackTrace();
- }
- return result;
- }
- }
|