Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1. package space_cheetah;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStreamWriter;
  7. import java.net.URL;
  8. import java.util.Base64;
  9.  
  10. import javax.net.ssl.HttpsURLConnection;
  11.  
  12. public class LifxMain
  13. {
  14.     public static void main(String[] args)
  15.     {
  16.         try
  17.         {
  18.             String token = "(removed access token):";
  19.             String basicAuthPayload = "Basic " + Base64.getEncoder().encodeToString(token.getBytes());
  20.             String url = "https://api.lifx.com/v1/lights/label:(removed label because I used my actual name)/state";
  21.             URL urlObj = new URL(url);
  22.             HttpsURLConnection connection = (HttpsURLConnection) urlObj.openConnection();
  23.             connection.setDoOutput(true);
  24.             connection.setDoInput(true);
  25.             connection.setRequestMethod("PUT");
  26.             connection.addRequestProperty("Authorization", basicAuthPayload);
  27.             OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
  28.             out.write(args[0]);
  29.             out.close();
  30.             connection.getInputStream();
  31.             StringBuffer requestParams = new StringBuffer();
  32.             BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  33.             String lineRead;
  34.             while((lineRead = reader.readLine()) != null)
  35.             {
  36.                 System.out.println(lineRead);
  37.             }
  38.         }
  39.         catch (IOException e)
  40.         {
  41.             e.printStackTrace();
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement