lundi 3 février 2020

Java if url response code = 200 then redirect

I want to check if an ip is alive and if not then redirect. And the below code give me a blank page.

public void main () throws Exception
    {

        URL url = new URL("https://192.168.1.1/");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();

        int code = connection.getResponseCode();
        if (code==200)
        {
        String current_url            = "https://192.168.1.1/";
        } else {
        String current_url    = "https://192.168.1.2/";
        }
    }

I'm Java newbie. Thanks in Advance

Aucun commentaire:

Enregistrer un commentaire