psot请求和get请求区别
post请求
第一种PoolingHttpClientConnectionManager
private static final PoolingHttpClientConnectionManager HTTP_CLIENT_CONNECTION_MANAGER;
private static final CloseableHttpClient HTTP_CLIENT;
static {
HTTP_CLIENT_CONNECTION_MANAGER = new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", SSLConnectionSocketFactory.getSocketFactory()).build());
HTTP_CLIENT_CONNECTION_MANAGER.setDefaultMaxPerRoute(2200);
HTTP_CLIENT_CONNECTION_MANAGER.setMaxTotal(2100);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(60000).setConnectTimeout(60000).setSocketTimeout(60000).build();
HTTP_CLIENT = HttpClientBuilder.create().setConnectionManager(HTTP_CLIENT_CONNECTION_MANAGER).setDefaultRequestConfig(requestConfig).build();
}
public static String post2(String cookies,String inviteId) {
Map<String, Object> headerMap = new HashMap<>();
headerMap.put("User-Agent", "jdapp");
headerMap.put("Accept-Language", "zh-cn");
headerMap.put("Accept-Encoding", "gzip, deflate, br");
String parameter = "xxxxxxx";
String url = "xxxxxxxxxxxxx";
String result = null;
try {
HttpPost httpPost = new HttpPost(url);
if (headerMap != null) {
headerMap.forEach((key, value) -> {
if (StringUtils.isNotEmpty(key)) {
httpPost.addHeader(key, value.toString());
}
});
}
StringEntity stringEntity = new StringEntity(parameter, ContentType.APPLICATION_FORM_URLENCODED);
httpPost.addHeader("Cache-Control", "no-cache");
httpPost.setEntity(stringEntity);
CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
result = EntityUtils.toString(httpEntity);
EntityUtils.consume(httpEntity);
}
httpResponse.close();
} catch (ParseException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result;
}