A simple Java code to use HTTP GET in Processing

import java.io.*;
import java.net.*;

String web_url = "https://www.google.com"; 

public class Web_access {

   public String getHTML(String urlToRead) {
      URL url;
      HttpURLConnection conn;
      BufferedReader rd;
      String line;
      String result = "";
      try {
         url = new URL(urlToRead);
         conn = (HttpURLConnection) url.openConnection();
         conn.setRequestMethod("GET");
         rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((line = rd.readLine()) != null) {
            result += line;
         }
         rd.close();
      } catch (IOException e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      }
      return result;
   }

}

void setup() {
  //nothing;
}



void draw() {
  Web_access c = new Web_access();
  
  println(c.getHTML(web_url));
  
  noLoop();
}
Advertisements