'HttpClient Tunnel failed, got: 502

I am trying to connect a endpoint through HttpClient in my Spring boot application getting Tunnel failed, got: 502 error. I could access through postman and able to see the response.

I am using same proxy connection as in postman while starting the application.

java.io.IOException: Tunnel failed, got: 502
    at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:565) ~[java.net.http:na]
    at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:119) ~[java.net.http:na]


Solution 1:[1]

Resolved by using RestTemplate instead of HttpClient. HttpClient not taken the JVM proxy details.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Balaji