Rest API call from java

Hello,

I am trying to call the Okta API from the Java code and getting “Connection Refused” exception. What could be the issue?

Code snippet used to connect (masked the URL and API Key):
String oktaAuthUrl = “XXXXXXXXXXXXXXXXXXXXXXXXXXXX/api/v1/users?limit=25”;
URL url = new URL(oktaAuthUrl);
conn = (HttpURLConnection) url.openConnection();
oktaapitoken = “#########################”;
conn.setRequestMethod(“GET”);
conn.setRequestProperty(“Accept”, “application/json”);
conn.setRequestProperty(“Content-Type”, “application/json”);
conn.setRequestProperty(“Cache-control”, “no-cache”);
conn.setRequestProperty(“Authorization”, “SSWS”+oktaapi);

		int responseCode = conn.getResponseCode();

Thanks in advance.

Error message :
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:442)
at sun.security.ssl.InputRecord.read(InputRecord.java:480)