I want to connect at login form开发者_如何学C. 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.)
- how can use my object connection for get html code after redirection?
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 :)
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.
精彩评论