We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone! I have a problem with HTTP request library. I use this code:
import http.requests.*;
import java.net.*;
import java.io.*;
import java.util.*;
String API="myApi"; // Api code
String answer="My answer"; // answer text
String messageTo="1111111"; // example integer
String urlAnswer = URLEncoder.encode(trim(answer)); // encode answer string
PostRequest post = new PostRequest("https://"+"api.telegram.org/bot"+API+"/sendmessage?chat_id="+messageTo+"&text="+urlAnswer);
post.send();
and status monitor show me this error message:
java.lang.NullPointerException
at http.requests.PostRequest.send(Unknown Source)
at sketch_160109a.setup(sketch_160109a.java:33)
at processing.core.PApplet.handleDraw(PApplet.java:2373)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1523)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
But GET request work perfect.
Can somebody explain me how I fix this problem?
I use Processing 3.0 on MacOS 10.9.5
Answers
Some trouble with code insert. Correct line: PostRequest post = new PostRequest("https://api.telegram.org/bot"+API+"/sendmessage?chat_id="+messageTo+"&text="+urlAnswer);
Separate the
http://
part from the rest of the URL when posting here to avoid the glitch: >-)It's my firs post! Thank's a lot! It's looks good now. But it's can't fix a real problem. ;)
Indeed. Perhaps the resultant URL passed to PostRequest's constructor isn't valid? :-/
If I past this url with correct API key and correct chat_id with some text in the end of this construction in web browser I have correct answer. The problem on Processing side.
I use code from HTTP request library example:
and I have the same problem.
Hey Yeah! I install old library 0.1.2 and my problem is gone!
an issue has been raised on the github repo for this bug (last october) but it hasn't been fixed yet
https://github.com/runemadsen/HTTP-Requests-for-Processing/issues/16
I don't know why, but new version (0.1.3) of HTTP request don't work correctly with POST method. I try add header fixes but nothing happened. At finally I install 0.1.2 version and problem is gone!
yes, 0.1.2 is fine. you lose BasicAuth capability (which you probably aren't using) but you don't get the null pointer exception.
Had the same problem. I can't seem to get 0.1.2 to work either though.
Different error. Can anyone help? Edit: This is for an Android app, incidentally. Maybe it is not intended for this?
Here's my utterly stripped down code, for which it still happens (for both POST and GET requests). I've tried 0.1.2 and the version previous to that (0.1 I think?)
Here's the error I get with the emulator:
and on my device:
I think I have the same problem sending POST and GET requests. I use latest version of HttpRequest (which is 0.1.4) and I use an Android device. After solving a lot of issues I ended with an error I cannot resolve. My code is
and the error I get is:
Has anyone succeeded sending post requests to a web page?....
The problem could be that HTTP Requests library uses an older version of Apache's HTTP Client.
Thank you for your answer. The solution then should come from the creators of the library by rebuilding it? Or maybe I could install an older Apache server edition?
If I were you, I'd just learn to use HTTP Client library directly.