Created
February 7, 2023 18:46
-
-
Save renaudfv/413a75f62ebd629fd575fb00a4d01b84 to your computer and use it in GitHub Desktop.
Processing sketch to send HTTP Get Requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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