HttpClient httpClient = HttpClientBuilder.create().useSystemProperties() .setMaxConnTotal([최대 커넥션 갯수]) .setMaxConnPerRoute([IP/domain name당 최대 커넥션 갯수]) ....
int timeout = 5; RequestConfig config = RequestConfig.custom() .setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000) .setSocketTimeout(timeout * 1000).build(); CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(config).build();
HttpClient
가 인지하지 못해서 클라이언트측에서 오류가 발생할 수 있다.HttpClient httpClient = HttpClientBuilder.create(). .evictIdleConnections(2000L, TimeUnit.MILLISECONDS) .... .build();
Please note this method has no effect if the instance of HttpClient is configuted to use a shared connection manager.
Please note this method may not be used when the instance of HttpClient is created inside an EJB container.
HttpProtocolParams.setContentCharset(httpParams, "UTF-8");
UrlEncodedFormEntity 클래스 생성자에서 문자 인코딩 지정
HttpPost post = new HttpPost("http://...."); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("paramName", "param value")); // params... post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
> HTTP specification permits both the client and the server to terminate a persistent (keep-alive) connection at any time without notice to the counterpart, thus rendering the connection invalid or stale. By default HttpClient performs a check, just prior to executing a request, to determine if the active connection is stale. The cost of this operation is about 15-30 ms, depending on the JRE used. Disabling stale connection check may result in slight performance improvement, especially for small payload responses, at the risk of getting an I/O error when executing a request over a connection that has been closed at the server side.
See the http.connection.stalecheck parameter documentation for more information.