title: C#: How to execute a HTTP request using sockets?
body: <p>I am trying to make a <code>HTTP request</code> using sockets. My code is as follows:</p>
  
  <pre><code>using System;
  using System.Net;
  using System.Net.Sockets;
  using System.Text;
  class test
  {
      public static void Main(String[] args)
      {
          string hostName = "127.0.0.1";
          int hostPort = 9887;
          int response = 0;
  
          IPAddress host = IPAddress.Parse(hostName);
          IPEndPoint hostep = new IPEndPoint(host, hostPort);
          Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  
          sock.Connect(hostep);
  
          string request_url = "http://127.0.0.1/register?id=application/vnd-fullphat.test&amp;title=My%20Test%20App";
          response = sock.Send(Encoding.UTF8.GetBytes(request_url));
          response = sock.Send(Encoding.UTF8.GetBytes("\r\n"));
  
          bytes = sock.Receive(bytesReceived, bytesReceived.Length, 0);
          page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes);
          Console.WriteLine(page);
          sock.Close();
      }
  }
  </code></pre>
  
  <p>Now when I execute the above code nothing happens whereas when I enter my <code>request_url</code> in browser I get a notification from Snarl saying that <code>Application Registered</code> and the response I get from browser is </p>
  
  <pre><code>SNP/2.0/0/OK/556
  </code></pre>
  
  <p>The response I get from my code is <code>SNP/3.0/107/BadPacket</code>.</p>
  
  <p>So, what is wrong with my code.</p>
  
  <p><a href="http://sourceforge.net/apps/mediawiki/snarlwin/index.php?title=SNP_2.0_API">Snarl Request format specification</a></p>