Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 12 commits ahead, 17 commits behind runemadsen:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib
resources
src/http/requests
web
.classpath
.gitignore
.project
README.md

README.md

Introduction

HTTP Requests for Processing is a small library that takes the pain out of doing HTTP requests in Processing.

HTTP Requests for Processing is based on code by Chris Allick and Daniel Shiffman.

This fork allows easy posting of json data, see bottom example. This was written in repsonse to this post on the processing forum: https://forum.processing.org/two/discussion/comment/50477

How to

Install the library by downloading the latest release or via the Processing contribution manager.

Then import the library in your sketch:

import http.requests.*;

Then you can make GET and POST requests from your code:

GetRequest get = new GetRequest("http://httprocessing.heroku.com");
get.send();
println("Response Content: " + get.getContent());
println("Response Content-Length Header: " + get.getHeader("Content-Length"));

PostRequest post = new PostRequest("http://httprocessing.heroku.com");
post.addData("name", "Rune");
post.send();
println("Response Content: " + post.getContent());
println("Response Content-Length Header: " + post.getHeader("Content-Length"));


// now with headers and json support
PostRequest post = new PostRequest("http://httprocessing.heroku.com");
post.addHeader("acdHeader", "hello world");
post.addJson("{\"items\": [{\"checked\": true, \"text\": \"one\"}, {\"checked\": true, \"text\": \"two\"}]}");
post.send();
println("Response Content: " + post.getContent());
println("Response Content-Length Header: " + post.getHeader("Content-Length"));


// now with binary support
PostRequest post = new PostRequest("http://httprocessing.heroku.com");
byte[] bytes = new byte[10];
for (int i = 0 ; i < byte.length ; i++) {
  bytes[i] = i;
}
post.addData("application/octet-stream", bytes);
post.send();
println("Response Content: " + post.getContent());
println("Response Content-Length Header: " + post.getHeader("Content-Length"));

// or from a file
post.addDataFromFile("image/jpeg", "/full/path/to/file.jpg");


// PUT support too
PostRequest put = new PostRequest("http://httprocessing.heroku.com", "ISO-8859-1");
put.method("PUT");
...
put.send();