문서의 이전 판입니다!
synchronized 블록이 있어서 일부 상황에서 멀티 쓰레드에서 동시 호출시 문제 발생소지가 있음. Java 17 이상에서는 괜찮음.connection, content-length, expect, host, upgrade)가 사라지는 현상이 발생한다.# 대소문자 안 가림 jdk.httpclient.allowRestrictedHeaders=host,content-length
SSLSocketImpl 이 사용되는 호출(https)시에 memory leak 발생finalzier 버그.Authorization 헤더 설정)HttpClient client = HttpClient.newBuilder() .authenticator(new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("<사용자명>", "<비번>".toCharArray()); } }) .build();
Authorization 헤더 직접 지정 방식. 단, authenticator 객체가 지정돼 있으면 Authorization 헤더 직접 지정은 작동하지 않는다.// header 직접 설정방식 private static final String getBasicAuthenticationHeader(String username, String password) { String valueToEncode = username + ":" + password; return "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes()); } HttpRequest request = HttpRequest.newBuilder() .GET() .uri(new URI("https://postman-echo.com/basic-auth")) .header("Authorization", getBasicAuthenticationHeader("<사용자명>", "<비번>")) .build();
jdk.httpclient.keepalive.timeout=1200 (초단위) 로 지정.jdk.httpclient.connectionPoolSize=0 0이면 무제한. 갯수로 지정.header(key, value) : 헤더를 추가한다.setHeader(key, value) : 헤더를 추가하면서 기존값이 있으면 덮어쓴다.HttpClient.newBuilder() .proxy(ProxySelector.getDefault()) .build();
HttpClient client = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress("www-proxy.com", 8080))) .build();