Please share your attempts and your efforts.
I have found a couple of post from previous posts:
- https://forum.processing.org/two/discussion/15978/sending-a-http-get-request
- https://forum.processing.org/two/discussion/22202/http-request
Below is an example using HTTP GET / and using loadString(). The value of OUTPUT_LEN defines the amount of data to output in the console.
Kf
//REFERENCES: Text only websites https://sjmulder.nl/en/textonly.html
//===========================================================================
// IMPORTS:
import http.requests.*;
//===========================================================================
// FINAL FIELDS:
final int OUTPUT_LEN=150;
final String[] urls = {
"http://www.example.com/",
"http://www.google.com/",
"http://lite.cnn.io/en/"
};
//===========================================================================
// PROCESSING DEFAULT FUNCTIONS:
void settings() {
size(400, 600);
}
void setup() {
textAlign(CENTER, CENTER);
rectMode(CENTER);
fill(255);
strokeWeight(2);
for (String url : urls) {
getRequest(url);
getData(url);
delay(2000); //NOT really needed but always be a good citizen
}
exit();
}
void draw(){}
//===========================================================================
// OTHER FUNCTIONS:
void getRequest(String url) {
GetRequest get = new GetRequest(url);
get.send();
String ret=get.getContent();
println("====================GET /===========================");
println("URL: ", url, "returned", ret.length(), "bytes (?)");
println("Response Content:", ret.substring(0, OUTPUT_LEN), "...");
}
void getData(String url) {
String[] str = loadStrings(url);
String ret=join(str, '\n');
println("====================LOADSTRING===========================");
println("URL: ", url, "returned", ret.length(), "bytes (?)");
println("Response Content:", ret.substring(0, OUTPUT_LEN), "...");
}