[an error occurred while processing this directive]
Domain for sale!
Start Search Contents Index Links About
GetResponse.java
/*
 * Author: Havard Rast Blok
 * E-mail:  
 * Web   : www.rememberjava.com
 */

import java.io.*;
import java.net.*;

/**
 * This small application takes an URL as argument, and
 * outputs the HTTP response
 
 * Refer to the main() method for how to read a local file instead.
 */
public class GetResponse  
{
  public GetResponseURL theURL )
  {

    HttpURLConnection con;
    int reCode;
    String reMessage;
    
    try
    {
      //get the HTTP response
      con = (HttpURLConnection)theURL.openConnection();
      reCode = con.getResponseCode();
      reMessage = con.getResponseMessage();
      System.out.println("HTTP response and message: " + reCode  + " - " + reMessage );
      
    }
    catchIOException e )
    {
      System.out.println"GetResponse.GetResponse - error opening or reading URL: " + e );
    }
  }
  
  
  public static void mainString args[] )
  {
    try
    {
      new GetResponse(new URL(args[0]));
      
      //Open file from disk instead
      //File f = new File( args[0] );
      //new GetResponse( f.toURL() );
    }
    catch (MalformedURLException e)
    {
      System.out.println("GetResponse.main - wrong url: " +e );
    }
    
  }
}


site: Håvard Rast Blok
mail:
updated: 16 July 2010