Example #1
0
  // HTTP GET request
  private static void sendGet() throws Exception {

    String url = Pinger.readXML("postAddress") + "?&ip=" + InetAddress.getLocalHost();

    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    // optional default is GET
    con.setRequestMethod(Pinger.readXML("method"));

    // add request header
    con.setRequestProperty("User-Agent", USER_AGENT);

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'GET' request to URL : " + url);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
      response.append(inputLine);
    }
    in.close();

    // print result
    System.out.println(response.toString());
  }
Example #2
0
  /** @param args */
  public static void main(String[] args) {
    while (true) {

      try {

        Thread.sleep(Integer.parseInt(Pinger.readXML("interval")) * 1000);

        System.out.println(InetAddress.getLocalHost());

        Pinger http = new Pinger();

        Pinger.sendGet();

      } catch (UnknownHostException e) {
        e.printStackTrace();
      } catch (NumberFormatException e1) {
        e1.printStackTrace();
      } catch (InterruptedException e1) {
        e1.printStackTrace();
      } catch (Exception e1) {
        e1.printStackTrace();
      }
    }
  }