For a supported HTTP or HTTPS URL connection, passing Proxy.NO_PROXY makes the direct choice explicit:

URLConnection connection = URI.create("https://example.com/")
    .toURL().openConnection(Proxy.NO_PROXY);
connection.setConnectTimeout(5000);
connection.setReadTimeout(10000);

This avoids a global set-and-restore sequence around one operation. Other threads can continue using the application's existing proxy policy.

The argument applies to this URLConnection path. It does not change a separate HTTP client's builder, another library's sockets, or the operating system's network configuration.

A direct connection can still fail if the network requires a proxy for external access. Keep that failure distinct from a proxy authentication error: this operation deliberately skipped the proxy.

Also preserve normal TLS verification for an HTTPS destination. Choosing a direct route changes the intermediary path; it does not change the identity the destination certificate must establish.

Tënë sô zo