| | |
| | | |
| | | private static final CloseableHttpClient httpclient = HttpClients.createDefault(); |
| | | |
| | | public static String doGet(String urlPath, Map<String, Object> params) |
| | | public static String doGet(String urlPath, Map<String, Object> params,String token) |
| | | throws Exception { |
| | | StringBuilder sb = new StringBuilder(urlPath); |
| | | if (params != null && !params.isEmpty()) { // 说明有参数 |
| | |
| | | |
| | | URL url = new URL(sb.toString()); |
| | | HttpURLConnection conn = (HttpURLConnection) url.openConnection(); |
| | | conn.setRequestProperty("auth", token); |
| | | conn.setConnectTimeout(5000); // 5s超时 |
| | | conn.setRequestMethod("GET"); |
| | | |
| | |
| | | //第三步:给httpPost设置JSON格式的参数 |
| | | StringEntity requestEntity = new StringEntity(json,"utf-8"); |
| | | requestEntity.setContentEncoding("UTF-8"); |
| | | httpPost.setHeader("Content-type", "application/json"); |
| | | httpPost.setHeader("Content-type", "application/x-www-form-urlencoded"); |
| | | httpPost.setHeader("Auth",token); |
| | | httpPost.setEntity(requestEntity); |
| | | |