Java And Url's are easy to work with. and here are a few ways: Getting text from a url: Code:JAVA try { // Create a URL for the desired page URL url = new URL("[url]http://hostname:80/index.html[/url]"); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { // str is one line of text; readLine() strips the newline character(s) } in.close();} catch (MalformedURLException e) {} catch (IOException e) {} Access a password protected url: Code:JAVA // Install the custom authenticatorAuthenticator.setDefault(new MyAuthenticator()); // Access the pagetry { // Create a URL for the desired page URL url = new URL("[url]http://hostname:80/index.html[/url]"); // Read all the text returned by the server BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { // str is one line of text; readLine() strips the newline character(s) } in.close();} catch (MalformedURLException e) {} catch (IOException e) {} public class MyAuthenticator extends Authenticator { // This method is called when a password-protected URL is accessed protected PasswordAuthentication getPasswordAuthentication() { // Get information about the request String promptString = getRequestingPrompt(); String hostname = getRequestingHost(); InetAddress ipaddr = getRequestingSite(); int port = getRequestingPort(); // Get the username from the user... String username = "myusername"; // Get the password from the user... String password = "mypassword"; // Return the information return new PasswordAuthentication(username, password.toCharArray()); }} Converting between a URI and a URL: Code:JAVA URI uri = null;URL url = null; // Create a URItry { uri = new URI("file://D:/almanac1.4/Ex1.java");} catch (URISyntaxException e) {} // Convert an absolute URI to a URLtry { url = uri.toURL();} catch (IllegalArgumentException e) { // URI was not absolute} catch (MalformedURLException e) {} // Convert a URL to a URItry { uri = new URI(url.toString());} catch (URISyntaxException e) {} Creating a URL: Code:JAVA try { // With components. URL url = new URL("http", "hostname", 80, "index.html"); // With a single string. url = new URL("[url]http://hostname:80/index.html[/url]");} catch (MalformedURLException e) {} Sending a POST Request Using a URL: Code:JAVA try { // Construct data String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8"); // Send data URL url = new URL("[url]http://hostname:80/cgi[/url]"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); wr.write(data); wr.flush(); // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { // Process line... } wr.close(); rd.close();} catch (Exception e) {} Parsing a URL: Code:JAVA try { URL url = new URL("[url]http://hostname:80/index.html#_top_[/url]"); String protocol = url.getProtocol(); // http String host = url.getHost(); // hostname int port = url.getPort(); // 80 String file = url.getFile(); // index.html String ref = url.getRef(); // _top_} catch (MalformedURLException e) {} Please enjoy!! Source: http://www.exampledepot.com/
HTML scrapping (Aka reading text from a page) is a great way to check if a plugin is up to date, in case anyone needs an example on what to use this with!