Hello everyone!
I’m working on the example of LEDs over the 'net,
a long time ago i did this example with HTML and
JavaScript, but now I want to do it from a java applet,
if anyone knows how to do it i’ll be waiting. I’m learning
and i don’t know how to make a POST request with java,
your help would be very useful.
Rather than waiting, try googling for a bit. Took me a good 10-20 seconds to find this, which seems nice: http://stackoverflow.com/questions/2793150/using-java-net-urlconnection-to-fire-and-handle-http-requests
Hi @Moors7 thank´s for your help, i´ve been searching a lot and i found this code
String urlParameters = "param1=a¶m2=b¶m3=c";
String request = "https://api.spark.io/v1/devices/" +deviceID + "/" + setFunc + "/";
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.disconnect();
But i don´t know how to put the params, i was thinking put something like this:
String urlParameters = "newValue, access_token: accessToken";