HTTP Client Connection in Java
<p>I am trying to make an HTTPClient connection using sockets and can't figure it out. When I run the code, I get the following message;</p>

<pre><code>HTTP/1.1 400 Bad Request
Date: Sun, 22 Apr 2012 13:17:12 GMT
Server: Apache/2.2.16 (Debian)
Vary: Accept-Encoding
Content-Length: 317
Connection: close
Content-Type: text/html; charset=iso-8859-1

&lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
&lt;html&gt;&lt;head&gt;
&lt;title&gt;400 Bad Request&lt;/title&gt;
&lt;/head&gt;&lt;body&gt;
&lt;h1&gt;Bad Request&lt;/h1&gt;
&lt;p&gt;Your browser sent a request that this server could not understand.&lt;br /&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;address&gt;Apache/2.2.16 (Debian) Server at pvs.ifi.uni-heidelberg.de Port 80&lt;/address&gt;
&lt;/body&gt;&lt;/html&gt;
</code></pre>

<p><strong>The code is here:</strong></p>

<pre><code>import java.net.*;
import java.io.*;

public class a1 {
  public static void main ( String[] args ) throws IOException {
    Socket s = null;

    try {
        String host = "host1";
        String file = "file1";
        int port = 80;
</code></pre>

<p><strong>Here I am creating the socket:</strong></p>

<pre><code>         s = new Socket(host, port);

        OutputStream out = s.getOutputStream();
        PrintWriter outw = new PrintWriter(out, false);
        outw.print("GET " + file + " HTTP/1.1\r\n");
        outw.print("Accept: text/plain, text/html, text/*\r\n");
        outw.print("\r\n");
        outw.flush();           

        InputStream in = s.getInputStream();
        InputStreamReader inr = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(inr);
        String line;

        while ((line = br.readLine()) != null) {
                System.out.println(line);
        }

    } 
    catch (UnknownHostException e) {} 
    catch (IOException e) {}

        if (s != null) {
                try {
                        s.close();
                }
                catch ( IOException ioEx ) {}
        }
  }
}   
</code></pre>

<p>Any help will be appreciated. Thank you.</p>
