Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 1st, 2011  |  syntax: Java  |  size: 1.17 KB  |  views: 115  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     private void upload(HttpServletRequest request, HttpServletResponse response) {
  2.         try {
  3.             String url = "http://api.photobucket.com/login/request  ";
  4.             URL endereco = new URL(url);
  5.             HttpURLConnection connection = (HttpURLConnection) endereco.openConnection();
  6.             connection.setRequestMethod("POST");
  7.             connection.setDoInput(true);
  8.             connection.setDoOutput(false);
  9.             connection.connect();
  10.  
  11.             // abre a conex√£o pra input
  12.             BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  13.             // le ate o final
  14.             StringBuffer newData = new StringBuffer(10000);
  15.             String s = "";
  16.             while (null != ((s = br.readLine()))) {
  17.                 newData.append(s);
  18.             }
  19.             br.close();
  20.  
  21.             System.out.println(new String(newData));
  22.             System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
  23.  
  24.  
  25.         } catch (Exception e) {
  26.             System.out.println("PHOTOBUCKET - UPLOAD");
  27.             System.out.println(e.getMessage());
  28.         }
  29.  
  30.     }