CHPP Development/Java/Login examples: Difference between revisions

From Hattrick
Jump to navigationJump to search
Filipx (talk | contribs)
No edit summary
 
Filipx (talk | contribs)
No edit summary
Line 2: Line 2:




public boolean getRecommendedServer() {
public boolean getRecommendedServer() {
   try {
   try {
       URL url = new URL("http://www.hattrick.org/Common/menu.asp?outputType=XML");
       URL url = new URL("http://www.hattrick.org/Common/menu.asp?outputType=XML");
Line 18: Line 18:
   }
   }
   return true;
   return true;
}
}

Revision as of 16:24, 17 February 2006

Step1: Getting the recommended server


public boolean getRecommendedServer() {
  try {
     URL url = new URL("http://www.hattrick.org/Common/menu.asp?outputType=XML");
     URLConnection connection = url.openConnection();
     BufferedReader br = new BufferedReader(
              new InputStreamReader(connection.getInputStream()));
     String line = "";
     while ((line = br.readLine()) != null) {
        //do something with the line
        //maybe write it into a file
     }
  } catch (Exception e) {
     e.printStackTrace();
     return false;
  }
  return true;
}