Zugbug

Untitled

Oct 13th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1.         String key = "--redacted--"; // key?
  2.         String message = "Hey from program!";   // message?
  3.         String url = "GET https://www.googleapis.com/gmail/v1/users/--redacted--/messages?includeSpamTrash=false&maxResults=10"
  4. //                + "&key='" + key + "'"//supposed to be authenticated in some way
  5.                 ;
  6.         HttpURLConnection con = (HttpURLConnection) new URL(url.split(" ")[1]).openConnection(); //open a new connection. Use second part of the URL as the destination.
  7.  
  8.         con.setRequestMethod(url.split(" ")[0]); //set the connections type to the http method, first part of the URL
  9.         con.setRequestProperty("key", key); //attempts to set HTTP headers, as in ContentType: "text/plain"
  10.  
  11.         String response = con.getResponseMessage(); //send the request and receive response, save the response into string
  12. //        System.err.println(con.getContent()); //prints response's body, errors in connection is not 200 OK
  13.         System.err.println(con.getHeaderFields()); //debug
  14.         System.err.println(con.getRequestMethod()); //debug
  15.         System.err.println(response); //print response
Advertisement
Add Comment
Please, Sign In to add comment