HTTP request java

By Sergio Filho, ago, written in Java.
URL http://pastecode.org/index.php/view/87969807
Download Paste or View RawExpand paste to full width of browser | Change Viewing Options
  1. import java.io.BufferedInputStream;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.net.HttpURLConnection;
  7. import java.net.MalformedURLException;
  8. import java.net.URL;
  9.  
  10. public class URLConnectionReader {
  11.         public static void main(String[] args) throws MalformedURLException, IOException{
  12.                    URL url = new URL("http://testeserjaum.appspot.com/");
  13.                    HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  14.                    System.out.println(urlConnection.getHeaderFields());
  15.                    try {
  16.                      InputStream in = new BufferedInputStream(urlConnection.getInputStream());
  17.                      BufferedReader buff = new BufferedReader(new InputStreamReader(in));
  18.                      System.out.println(buff.readLine());
  19.                    }finally{
  20.                      urlConnection.disconnect();
  21.                    }
  22.  
  23.         }
  24. }
  25.  

Here you can reply to the paste above

Make Private

   

Feeling clever? Set some advanced options.