I'm trying to connect to a website and to send many different post requests through different pages all over the website. I've reached the first step:connect the website. But now, I need to change the request url and keeping the same httpURLConnection.
For now my code is:
//openning the connection to the website
URL url = new URL("http://path/to/the/website");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setDoOutput(true);
        //preparing the post arguments
        Map<String, Object> params = new HashMap<>();
        params.put("Action", "connect_user");
        params.put("login", "login");
        params.put("password", "password");
        StringBuilder sb = new StringBuilder();
        for (Entry<String, Object> e : params.entrySet()) {
            if (sb.length() != 0)
                sb.append('&');
            sb.append(URLEncoder.encode(e.getKey(), "UTF-8"));
            sb.append('=');
            sb.append(URLEncoder.encode(String.valueOf(e.getValue()), "UTF-8"));
        }
        //writing the request and sending
        BufferedOutputStream writer = new BufferedOutputStream(conn.getOutputStream());
        writer.write(sb.toString().getBytes(Charset.forName("UTF-8")));
        writer.flush();
At this step i'm connected and sucessfully logged in. What I need to do now is to redirect the same connection to a second url. Thanks.