Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package space_cheetah;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.URL;
- import java.util.Base64;
- import javax.net.ssl.HttpsURLConnection;
- public class LifxMain
- {
- public static void main(String[] args)
- {
- try
- {
- String token = "(removed access token):";
- String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(token.getBytes());
- String url = "https://api.lifx.com/v1/lights/label:(removed label because I used my actual name)/state";
- URL urlObj = new URL(url);
- HttpsURLConnection connection = (HttpsURLConnection) urlObj.openConnection();
- connection.setDoOutput(true);
- connection.setDoInput(true);
- connection.setRequestMethod("PUT");
- connection.addRequestProperty("Authorization", basicAuthPayload);
- OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
- out.write(args[0]);
- out.close();
- connection.getInputStream();
- StringBuffer requestParams = new StringBuffer();
- BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String lineRead;
- while((lineRead = reader.readLine()) != null)
- {
- System.out.println(lineRead);
- }
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement