import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;

//-------------------------------------------------------------------
public class HTTP {
  public final static int HTTP_PORT = 80;
  InetAddress wwwHost;
  DataInputStream in;
  PrintStream out;
  public HTTP (String host) throws UnknownHostException
  {
    wwwHost = InetAddress.getByName(host);
  }
  public BufferedReader get (String file) throws IOException {
    Socket httpPipe;
    InputStream inn;
    OutputStream outt;
    BufferedReader ir;
    PrintWriter out;
    httpPipe = new Socket (wwwHost, HTTP_PORT);
    if (httpPipe == null) {
      return null;
    }
    inn  = httpPipe.getInputStream();
    outt = httpPipe.getOutputStream();
    ir   = new BufferedReader (new InputStreamReader (inn));
    out  = new PrintWriter (new OutputStreamWriter (outt), true);

    if (inn==null || outt==null || ir==null || out==null) {
         JOptionPane.showMessageDialog(null,"verilen kanala ulaşılamadı ",
            "URL adresinde hata var",JOptionPane.ERROR_MESSAGE );
      return null;
    }
    out.println ("GET " + file + " HTTP/1.0\n");
    String response;
    while ((response = ir.readLine()).length() > 0) {}
    return ir;
  }
}
