javahttpsurlconnection

how to i set HttpsURLConnection connectTimeout greater than 60 seconds


Hie, I am having an issue where the HttpsURLConnection is timing out at 60 seconds even though i set connection timeout greater than 60 seconds. If i set the connection timeout to less than 60000 (60 seconds), it times out the set time, anything above 60 seconds

            URL obj = new URL(url);
            
           
            HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
            
            con.setRequestMethod("POST");
            con.setRequestProperty("Content-Type", "application/json; utf-8");
            con.setRequestProperty("Accept", "application/json");
            con.setConnectTimeout(180000);
            con.setReadTimeout(240000);
                        
            con.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(con.getOutputStream());
            wr.writeBytes(payload.toString());
            wr.flush();
            wr.close();

            int responseCode = con.getResponseCode();

            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

Solution

  • It is possible that it is not your connection that times out. It can be the server side that times out, or it can be the proxy,gateway in between.