Login ohne Erfolg

cX_Java

Mitglied
Hi ihr alle,

habe folgendes Problem:

Ich wollte mich per URLConnection auf einer Webseite einloggen und den Quellcode auslesen, alles was ich aber zurück bekomme ist ein:
HTML:
<script>document.location.href='http://xyz.de'</script>

ich habe leider noch keine Erfahrungen mit java.net.* und wollte jetzt mal wissen woran das grundsäztlich liegen könnte, dass ich zurück auf die Ursprungs-url geleitet werde.

Mfg cX_Java
 
Die URLConnection wertet den String nunmal nicht aus.
Der Browser würde diesen String empfangen, das script ausführen und damit auf die Seite
Code:
http://xyz. de
weiterleiten.
Das müsstest du händisch machen.
 
soweit hab ich das verstanden, aber warum leitet er mich auf die ursprungs url zurück? ich will ja sozusagen in den "login" Bereich und nicht wieder auf die seite von der ich mich einlogge, ich denk mal es stimmt irgendwas mit dem login nicht aber ich weiß nicht was^^

Java:
        public static void main(String[] args) {
		try {
			// Set up the URL
			String url = "http://xyz.de/login.php";
			String charset = "UTF-8";

			String query = 
				"param1=" + URLEncoder.encode("", charset) +"&"+
				...
				"paramN=" + URLEncoder.encode("", charset);

			
			// Set up the connection
			URLConnection connection = new URL(url).openConnection();
			
			// First a GET to gather cookies (or submit a login form using POST).
			List<String> cookies = connection.getHeaderFields().get("Set-Cookie");
			
			// Then a subsequent POST with cookies.
			connection = new URL(url + "?" + query).openConnection();
			connection.setDoOutput(true); // Triggers POST.
			connection.setRequestProperty("Accept-Charset", charset);
			connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
			connection.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0");
			for (String cookie : cookies) {
			    connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]);  
			}
			
			
			OutputStream output = null;
			try {
			     output = connection.getOutputStream();
			     output.write(query.getBytes(charset));
			} finally {
			     if (output != null) try { output.close(); } catch (IOException logOrIgnore) {}
			}


			// Read the source code
			InputStream response = connection.getInputStream();
			Scanner scanner = new Scanner(response);
			while (scanner.hasNextLine()) {
                System.out.println(scanner.nextLine());
            }

		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

soweit ich sagen kann stimmen die Parameter, wenn ich einen weglasse wird der Quelltext der Seite
HTML:
http://xyz.de
ausgelesen, wenn ich alle richtig eingebe kommt dieser scriptaufruf von oben, leider jedoch zur falschen seite, ich denke mal, dass das eine art sicherung vor spambots ist.
 

Zurück
Oben