| | |
| | | } |
| | | |
| | | //适用于post请求并传送form-data数据(同样适用于post的Raw类型的application-json格式) |
| | | public static String postParams(String url, String appKey, String appKeyValue, Map<String, String> map) { |
| | | public static String postParams(String url, String appKey, Map<String, String> map) { |
| | | SSLContext sslcontext = null; |
| | | try { |
| | | sslcontext = createIgnoreVerifySSL(); |
| | |
| | | //创建自定义的httpclient对象 |
| | | CloseableHttpClient client = HttpClients.custom().setConnectionManager(connManager).build(); |
| | | HttpPost post = new HttpPost(url); |
| | | post.setHeader(appKey, appKeyValue); |
| | | post.setHeader("appKey", appKey); |
| | | CloseableHttpResponse res = null; |
| | | try { |
| | | List<NameValuePair> nvps = new ArrayList<NameValuePair>(); |
| | |
| | | CloseableHttpClient httpClient = HttpClients.createDefault(); |
| | | try { |
| | | BasicResponseHandler handler = new BasicResponseHandler(); |
| | | StringEntity entity = new StringEntity(json, "utf-8");//解决中文乱码问题 |
| | | //解决中文乱码问题 |
| | | StringEntity entity = new StringEntity(json, "utf-8"); |
| | | entity.setContentEncoding("UTF-8"); |
| | | entity.setContentType("application/json"); |
| | | httpPost.setEntity(entity); |
| | |
| | | return result; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | } finally { |
| | | try { |
| | | httpClient.close(); |