0

I want to connect at login form. I send informations for connections. The problem, after identification, the website do a redirection and when i test my Object HttpsURLConnection with method connection.getResponseCode(), i have code 302 (HTTP Status-Code 302: Temporary Redirect.)

  1. how can use my object connection for get html code after redirection?
  2. How can use my connetion for navigate in all site after connection?

        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
    
        request.write("login=ll&password=pp");
        request.flush();
        request.close();            
        String line = "";               
        InputStreamReader isr = new InputStreamReader(connection.getInputStream());
        //.... get string
    

thx for your answer :)

1 Answers1

0

You can read the location header to see where you've been redirected to

String header = connection.getHeaderField("location");

and then open a new connection to that URL.

You are most likely being redirected from HTTPS (login) to HTTP (post login). See this answer to another question for information on why HttpURLConnection is not automatically following the redirect in this case.

Community
  • 1
  • 1
ewan.chalmers
  • 16,145
  • 43
  • 60
  • thx for get next url but when i open a new connection at this adress, he don't have logged. When i send a bad password, i have error message. If i have put good password, i have redirection. how HttpsURLConnection get sessions? i need get another informations? – lucianot54 May 13 '11 at 15:29