Skip to content

Instantly share code, notes, and snippets.

@renaudfv
Created February 7, 2023 18:46
Show Gist options
  • Save renaudfv/413a75f62ebd629fd575fb00a4d01b84 to your computer and use it in GitHub Desktop.
Save renaudfv/413a75f62ebd629fd575fb00a4d01b84 to your computer and use it in GitHub Desktop.
Processing sketch to send HTTP Get Requests
import java.net.http.*;
import java.net.URI;
import java.net.http.HttpResponse.BodyHandlers;
void sendReq() {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://google.com/"))
.build();
client.sendAsync(request, BodyHandlers.ofString())
.thenAccept(this::handleRes)
.join();
}
void handleRes(HttpResponse res) {
println("Status " + res.statusCode());
println("Headers " + res.headers());
println("Body " + res.body());
}
void setup() {}
void draw() {
if(frameCount % 100 == 0)
sendReq();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment