Posted By

jerryvig on 02/27/12


Tagged

java xml groovy delicious https


Versions (?)

Delicious API Https Authentication in Java/Groovy


 / Published in: Groovy
 

This is an example of how to download the favorites XML file from Delicious using the java.net classes and doing the HTTPS password authentication to obtain access. This script is written in Groovy but you can translate it to plain java pretty easily by getting rid of the dynamic typing and using semicolons.

  1. import javax.net.ssl.HttpsURLConnection
  2. import java.net.*
  3. import java.io.*
  4.  
  5. PasswordAuthentication getPasswordAuthentication() {
  6. def username = "myusername"
  7. def pass = "mypassword"
  8. return new PasswordAuthentication(username,pass.toCharArray())
  9. }
  10. });
  11.  
  12. def url = new URL("https://myusername:[email protected]/v1/posts/all")
  13. def conn = (HttpsURLConnection)url.openConnection()
  14. def reader = new BufferedReader(new InputStreamReader(conn.getInputStream()))
  15. def outFile = new File("/tmp/all.xml")
  16. outFile.delete()
  17. def line;
  18. while ((line = reader.readLine()) != null) {
  19. outFile << line
  20. }
  21. reader.close()

Report this snippet  

You need to login to post a comment.