Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OkHttpClient - Ignore proxy from system properties

Tags:

java

rest

okhttp

I have a web container (Glassfish) with a proxy configured on its system properties for one application.

Now i have another application on the same web container and would like to customize proxy usage via code using OkHttpClient.

The problem is that OkHttpClient is automatically using the proxy configured in system properties. Here is my code to instantiate a HTTP client:

        httpClient = new OkHttpClient.Builder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .build();

When i try to do a GET request, it fails telling me that it couldn't connect via the specified proxy host. Is there a way to ignore a proxy on system properties?

like image 547
Diego Victor de Jesus Avatar asked Sep 10 '26 14:09

Diego Victor de Jesus


1 Answers

Try this:

    httpClient = new OkHttpClient.Builder()
            .proxy(Proxy.NO_PROXY)
            .build();
like image 64
Jesse Wilson Avatar answered Sep 12 '26 04:09

Jesse Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!