title: Writing a "raw" HTTP client in C#
body: <p>I am trying to write a "raw" HTTP client in C#. You may ask why?? </p>
  
  <p>My aim is to implement an HTTP client in J2ME (which can only do GET and limited POST), but first I need to understand the HTTP protocol better (hence the C# attempt).</p>
  
  <p>My first attempts are failing:</p>
  
  <pre><code>var requestBytes = Encoding.UTF8.GetBytes(@"GET / HTTP/1.1
  User-Agent: CSharp
  Host: www.google.com
  
  ");
  var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  socket.Connect("www.google.com", 80);
  socket.Send(requestBytes);
  var responseBytes = new byte[socket.ReceiveBufferSize];
  socket.Receive(responseBytes);
  Console.Out.Write(Encoding.UTF8.GetString(responseBytes));
  </code></pre>
  
  <p>The socket opens, but then blocks at the Receive call. After a couple of seconds the remote host closes the connection.</p>
  
  <p>Any ideas?</p>
  
  <p>The same happens when I try to connect using the RAW mode in puTTY.</p>