Ik ben bezig met het maken van een inlogsysteem voor een spel wat ik speel, hiermee wil ik later waardes gaan berekenen, maar daarvoor dien ik eerst ingelogd te zijn om deze waardes te kunnen zien. Nu heb ik veel rond gekeken en ben ik uiteindelijk tot de volgende code gekomen.
Ik krijg het volgende terug:
Om via de 'normale' XML-url in te loggen gebruik ik: http://www.maxithlon.com/...ser=Gynnad&scode=1q2w3e4r
Gynnad is hierbij de gebruikersnaam
1q2w3e4r is hierbij de securitycode (deze is anders dan het wachtwoord, maar nodig om tot de XML bestanden te komen)
Nu is mijn vraag zit er een fout in mijn code of gebruikt Maxithlon een andere POST methode?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
| /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Connection; /** * * @author Danny */ import java.net.*; import java.io.*; public class ConnectToURL { // Variables to hold the URL object and its connection to that URL. private static URL URLObj; private static URLConnection connect; public static void main(String[] args) { try { // Establish a URL and open a connection to it. Set it to output mode. //login link: http://www.maxithlon.com/maxi-xml/login.php?user=Gynnad&scode=1q2w3e4r URLObj = new URL("http://www.maxithlon.com/maxi-xml/login.php"); connect = URLObj.openConnection(); connect.setDoOutput(true); } catch (MalformedURLException ex) { System.out.println("The URL specified was unable to be parsed or uses an invalid protocol. Please try again."); System.exit(1); } catch (Exception ex) { System.out.println("An exception occurred. " + ex.getMessage()); System.exit(1); } try { // Create a buffered writer to the URLConnection's output stream and write our forms parameters. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream())); writer.write("user=Gynnad&scode=1q2w3e4r"); //username=MyUsername&pass=MyPassword&submit=Login (Origineel van de tutorial) //user=Gynnad&scode=1q2w3e4r (dit is wat de weburl zelf gebruikt) writer.close(); // Now establish a buffered reader to read the URLConnection's input stream. BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream())); String lineRead = ""; // Read all available lines of data from the URL and print them to screen. while ((lineRead = reader.readLine()) != null) { System.out.println(lineRead); } reader.close(); } catch (Exception ex) { System.out.println("There was an error reading or writing to the URL: " + ex.getMessage()); } } } |
Ik krijg het volgende terug:
code:
1
2
3
4
| <?xml version="1.0" encoding="utf-8"?> <maxi-xml> <error>Login failed</error> </maxi-xml> |
Om via de 'normale' XML-url in te loggen gebruik ik: http://www.maxithlon.com/...ser=Gynnad&scode=1q2w3e4r
Gynnad is hierbij de gebruikersnaam
1q2w3e4r is hierbij de securitycode (deze is anders dan het wachtwoord, maar nodig om tot de XML bestanden te komen)
Nu is mijn vraag zit er een fout in mijn code of gebruikt Maxithlon een andere POST methode?
"Don't worry, about a thing, Cause every little thing is gonna be alright"