Coder Social home page Coder Social logo

http-requests-for-processing's Introduction

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.

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("Reponse Content: " + get.getContent());
println("Reponse Content-Length Header: " + get.getHeader("Content-Length"));
    
PostRequest post = new PostRequest("http://httprocessing.heroku.com");
post.addData("name", "Rune");
post.send();
println("Reponse Content: " + post.getContent());
println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));

To authenticate requests using a Basic Access authentication scheme, include the following in your requests:

get.addUser("username", "password");
post.addUser("username", "password");

To add a header to your request, including the following:

 //method: addHeader(name,value)
 get.addHeader("Accept", "application/json");
 post.addHeader("Content-Type", "application/json");

http-requests-for-processing's People

Contributors

bnsh avatar brodan avatar emilesilvis avatar leandro-navarro avatar mactkg avatar nullboundary avatar peteruithoven avatar renato776 avatar runemadsen avatar shiffman avatar tigoe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

http-requests-for-processing's Issues

build.xml?

With the new structure you're suggesting building the library with ant, but I think you'll need your build.xml file in the repo for users to do so?

Help me !!

Hello I'm trying to use a json's post but the addData function doesn't understand json to compose the request, I tried the example that is available, but an error appears (the "addData" function expects parameters like "addData (String, String)" in my http server along with my api in the postman is working, I wanted to test with processing, could help me.
ErrorPostJson

rename and package for 2.0

I just remembered that i have on my todo list to help package this lib up for 2.0 and rename to "HTTPRequests for Processing". So just adding an issue to take care of this, can also deal with #4 in tandem.

Response Code

Dear, I would like to know how I could insert a variable of the integer type to receive the response code of the request that was made. I thank the attention

installing from the contribution manager

I try to install the library from the contribution manager in Processing 3.3.6 on OSX.
I get the announcement: Could not find a library in the downloaded file.

screen shot 2018-12-12 at 14 20 11

PostRequest.addFile data type File

It may just be that I am stupid and maybe missed something, but I've run into a problem with the addFile command. It requires a File datatype, but I am unaware on how to get those.

What I am trying to do is to upload a JPEG File to my server via a post request. For that I have this code:

void keyReleased() {
  PImage img = get();
  img.save(fileName);
  PostRequest post = new PostRequest(upload_Skript_Address);
  post.addFile("file",someFile); //needs File type object (What datatype is that? Where do I get it?)
  post.send();
  println("Reponse Content: " + post.getContent());
  println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
}

But as you may read, I need a File object which I don't know how to get. Do please help if you have any idea (even if it was a only a Google search away [though that would be quite embarassing])

License

Hi! Thank you for sharing your work. I noticed that on the Processing website, this project was listed as a community-contributed library (https://processing.org/reference/libraries/):

Contributed libraries are created by members of the Processing community. They are independently and generously created to share. They are all open source and include their own reference and examples.

Of course, there are a wide variety of open-source licenses to choose from, with varying consequences for licensees. I want to be respectful of the project's decision here, but I can't seem to find a license for this library in the repository - would you mind specifying the license under which this code is made available?

specifiying port number

I want to use this library with the da different port number.. is there a function for it ?

java.lang.NoSuchMethodError: No static method consume()V in class EntityUtils

I’m using Processing 3.5.4 on Windows 10. I’ve created a script using HTTP Requests library. Everything works fine.
Now I’m trying to run the script on my Android phone with APDE v0.5.1. I've installed httprequests_processing.zip and receive following error. Any advice?

Thread-8686(ApacheHTTPLog):Reading from variable values from setDefaultValuesToVariables
Thread-8686(ApacheHTTPLog):isSBSettingEnabled false
Thread-8686(ApacheHTTPLog):isShipBuild true
Thread-8686(ApacheHTTPLog):getDebugLevel 0x4f4c
Thread-8686(ApacheHTTPLog):Smart Bonding Setting is false
Thread-8686(ApacheHTTPLog):SmartBonding Setting is false, SHIP_BUILD is true, log to file is false, DBG is false, DEBUG_LEVEL (1-LOW, 2-MID, 3-HIGH) is 1
Animation Thread calls detatch()
java.lang.NoSuchMethodError: No static method consume(Lorg/apache/http/HttpEntity;)V in class Lorg/apache/http/util/EntityUtils; or its super classes (declaration of 'org.apache.http.util.EntityUtils' appears in /system/framework/org.apache.http.legacy.jar)
	at http.requests.PostRequest.send(Unknown Source:209)

Request via HTTPS scheme not possible

Installed dependencies
Processing 3.5.4
HTTP-Requests-for-Processing: 0.1.5
Android Mode: 4.2.1

Code

import http.requests.*;

public void setup() {
  size(400, 400);

  GetRequest get = new GetRequest("https://ipinfo.io/json");
  get.send(); // d program will wait untill the request is completed
  println("response: " + get.getContent());
  JSONObject response = parseJSONObject(get.getContent());
  println("status: " + response.getString("status"));
  println("data: " + response.getJSONObject("data"));
}

and added <uses-permission android:name="android.permission.INTERNET"/> to the related AndroidManifest.xml

Output

...
BUILD SUCCESSFUL in 19s
25 actionable tasks: 25 executed
FATAL EXCEPTION: Animation Thread
Process: processing.test.test, PID: 22245
java.lang.IncompatibleClassChangeError: Class 'org.apache.http.conn.ssl.SSLSocketFactory' does not implement interface 'org.apache.http.conn.scheme.SchemeSocketFactory' in call to 'java.net.Socket org.apache.http.conn.scheme.SchemeSocketFactory.createSocket(org.apache.http.params.HttpParams)' (declaration of 'org.apache.http.impl.conn.DefaultClientConnectionOperator' appears in /data/app/processing.test.test-cwaQQ5qAEO9ZXXlmvpNwWQ==/base.apk)
	at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
	at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
	at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
	at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
	at http.requests.GetRequest.send(Unknown Source:61)
	at processing.test.test.test.setup(test.java:43)
	at processing.core.PApplet.handleDraw(PApplet.java:1878)
	at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:478)
	at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:518)

Expected behaviour
Get data from ipinfo.io and print it

When using HTTP instead of HTTPS, all works fine.

http delete request

Is there a way I can send a delete request using this libary? and if so, how do I do this?

multipart/form-data support ?

Hi, I'm trying to implement a file sender for a Telegram BOT, working around with addFile. The request needs to be made with multipart/form-data as Content-Type and structure. Is there a way to change the MultipartEntity mode?

HTTPS GET "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated" while using typeform response API

When I tried

import http.requests.*;

public void setup() 
{
	size(400,400);
	smooth();
	
  GetRequest get = new GetRequest("https://api.typeform.com/forms/DxlTiK/responses");
   get.addHeader("Authorization", "Bearer {MyTokenCode}");
  
  get.send(); // program will wait untill the request is completed
  println("response: " + get.getContent());

  JSONObject response = parseJSONObject(get.getContent());
  println("status: " + response.getString("status"));
  JSONArray boxes = response.getJSONArray("data");

}

I get following error message:

javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
response: null
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:397)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:149)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:573)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
at http.requests.GetRequest.send(Unknown Source)
at sketch_20190114_Song_for_Film_.setup(sketch_20190114_Song_for_Film_.java:30)
at processing.core.PApplet.handleDraw(PApplet.java:2361)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:240)
at processing.core.PApplet.run(PApplet.java:2256)
at java.lang.Thread.run(Thread.java:745)

Adding a body to a post request

How can I add a body to a post request? Is there a function I could use like write()? Or some type of workaround?

I want to pass this json info as the body of the request:
{ "url": "http://example.com/picture.jpg" }

Thanks :)

Small typo in example jsonpost.pde

Hello,
just found this and it seems to be what I am looking for ...but:

In jsonpost.pde it should be
post.addHeader("Content-Type", "application/json");
instead of
put.addHeader("Content-Type", "application/json");
....
That aside, is this supposed to work on Andriod/APDE?

HTTP POST request for sending a file to the server

How do I go about posting a file (eg. a picture) using POST request from this library. How to write the file data on the server(as we did with server.write(filedata);)? What headers to explicitely include using addHeader(); ?

HTTP POST returns null pointer exception

Hi there,

for some reason when I run the post example, the response content is null resulting in a Null Pointer Exception. I've tried it on both Processing 2.2.1 and Processing 3.

HOWEVER, a friend of mine tried it on their computer on Processing 2.2.1 with the same version of Java and it worked. We both have macs.
Why is it that this library works on some computers and not others? Does it have something to do with my operating system? I have OS X Yosemite 10.10.3

This is the code that I am trying to get to work. It's a very basic HTTP Post that works perfectly with the curl command in terminal. This code worked on my friend's computer as well just like the post example:

import http.requests.*;

public void setup()
{
size(400,400);
smooth();
PostRequest post = new PostRequest("http://text-processing.com/api/sentiment/");
post.addData("text", "good");
post.send();
System.out.println("Reponse Content: " + post.getContent());
System.out.println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
}

POST Body plain/text

Is it possible to make a POST request with just plain text? I followed this link to allow for sending JSON and I tried adapting it so I could send text but it did not work.

I am trying to emulate this POST request from postman in Processing.

image

very new html features problem... (youtube live chat)

Hello, the problem appears as I try to use GET from the popout chat of a live YouTube video:

Reponse Content: <style nonce="+glrZXZT5SrXVG9iZMLTqA">html,body,#page,#content-container{width:100%;height:100%;margin:0;padding:0}body{background-color:#fff;color:hsl(0,0%,6.7%);font-family:Roboto,Arial,sans-serif}a{color:hsl(0,0%,20%);font-size:20px}#content-container{position:relative}#content{position:absolute;top:50%;left:0;right:0;transform:translate(0,-50%);text-align:center}h1{font-size:48px}</style><style name="www-roboto" nonce="+glrZXZT5SrXVG9iZMLTqA">@font-face{font-family:'Roboto';font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxP.ttf)format('truetype');}</style><script name="www-roboto" nonce="WU6AsU0EzQdRs5G2xVigiw">if (document.fonts && document.fonts.load) {document.fonts.load("400 10pt Roboto", "P"); document.fonts.load("500 10pt Roboto", "P");}</script>

Ah, não!

Parece que a versão do seu navegador é antiga. Atualize para usar o chat ao vivo.


Reponse Content-Length Header:

The last part the important one, although in Portuguese, sorry, Brazilian server.... it says something like "your browser version seems old, please update to use the live chat"
I imagine you guess I'm trying to pick up the live comments... soon help would be really, really appreciated!

how to get mp3 file ??

hey i want the callback function from "get.content" return byte not string, because my http server return bytes format, how can i achieve this ?? thx :)

android issue FATAL EXCEPTION:

i'm testing with really simple android app which save the captured image then upload to the server
on each time during the http post session the app got crashed,reported as following:

FATAL EXCEPTION: Animation Thread
java.lang.NoSuchMethodError: org.apache.http.util.EntityUtils.consume
at http.requests.PostRequest.send(Unknown Source)
at processing.test.android_image.android_image.postImg(android_image.java:145)
at processing.test.android_image.android_image.draw(android_image.java:56)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:841)

but without any issue running on desktop. any ideas?

Edit request headers before send it.

I don't know if this is the right place to post this. Here it goes anyway.

Is there any method to add / remove / edit the request headers before sending it ?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.