문서의 선택한 두 판 사이의 차이를 보여줍니다.
다음 판 | 이전 판 마지막 판 양쪽 다음 판 | ||
java:httpclient [2020/08/06 12:54] kwon37xi 만듦 |
java:httpclient [2023/11/28 10:34] kwon37xi [일부 헤더가 사라지는 문제] |
||
---|---|---|---|
줄 1: | 줄 1: | ||
====== Java HttpClient ====== | ====== Java HttpClient ====== | ||
* [[https:// | * [[https:// | ||
+ | * Apache 것은 [[java: | ||
+ | |||
+ | ===== 주의 ===== | ||
+ | ==== 성능 이슈 ==== | ||
+ | * Java 17 미만 버전의 Http Client 는 '' | ||
+ | * [[https:// | ||
+ | |||
+ | ==== 일부 헤더가 사라지는 문제 ==== | ||
+ | * 일부 헤더('' | ||
+ | * 보안을 위해 '' | ||
+ | * 이것은 문제는 아니고, 의도된 것인데 System Property 를 지정해주면된다. 호출이 일어날 때마다 프라퍼티 확인 | ||
+ | < | ||
+ | # 대소문자 안 가림 | ||
+ | jdk.httpclient.allowRestrictedHeaders=host, | ||
+ | # sec- 헤더는 이것만으로는 해결이 안됨. | ||
+ | </ | ||
+ | * 참조 : [[https:// | ||
+ | * 헌데, '' | ||
+ | ==== SSL 에서 memory leak ==== | ||
+ | * [[https:// | ||
+ | * Java 19 미만 버전의 경우 '' | ||
+ | * '' | ||
+ | |||
+ | |||
+ | ===== 인증 / Authentication ===== | ||
+ | * [[https:// | ||
+ | * Basic Auth('' | ||
+ | <code java> | ||
+ | HttpClient client = HttpClient.newBuilder() | ||
+ | .authenticator(new Authenticator() { | ||
+ | @Override | ||
+ | protected PasswordAuthentication getPasswordAuthentication() { | ||
+ | return new PasswordAuthentication("< | ||
+ | } | ||
+ | }) | ||
+ | .build(); | ||
+ | </ | ||
+ | * '' | ||
+ | * [[https:// | ||
+ | <code java> | ||
+ | // header 직접 설정방식 | ||
+ | private static final String getBasicAuthenticationHeader(String username, String password) { | ||
+ | String valueToEncode = username + ":" | ||
+ | return "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes()); | ||
+ | } | ||
+ | |||
+ | HttpRequest request = HttpRequest.newBuilder() | ||
+ | .GET() | ||
+ | .uri(new URI(" | ||
+ | .header(" | ||
+ | .build(); | ||
+ | </ | ||
+ | ===== Connection Pool ===== | ||
+ | * Keep Alive Timeout : System Property '' | ||
+ | * Connection Pool Max Size : System Property '' | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ===== HttpRequestBuilder ===== | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Proxy ===== | ||
+ | ==== System 설정값 따르기 ==== | ||
+ | <code java> | ||
+ | HttpClient.newBuilder() | ||
+ | .proxy(ProxySelector.getDefault()) | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | ==== 명시적 지정 ==== | ||
+ | <code java> | ||
+ | HttpClient client = HttpClient.newBuilder() | ||
+ | .proxy(ProxySelector.of(new InetSocketAddress(" | ||
+ | .build(); | ||
+ | |||
+ | </ | ||
===== 참조 ===== | ===== 참조 ===== | ||
줄 6: | 줄 83: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
* [[https:// | * [[https:// | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
- | * [[https://www.youtube.com/watch? | + | * [[https://golb.hplar.ch/2019/ |
- | * [[https:// | + | * [[https:// |
- | + | * [[https:// | |
+ | * [[https:// | ||
+ | * [[https://dzone.com/ | ||
+ | * [[https:// | ||
+ | * https:// |