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