title: POST request using sockets C#
body: <p>I'm trying to make an auction sniper for a site. To place a bid you need to send 4 parameters(and cookies of course) to /auction/place_bid. I need to use sockets, not HttpWebRequest. Here's the code:</p>
  
  <pre><code>        string request1 = "POST /auction/place_bid HTTP/1.1\r\nHost: *host here*\r\nConnection: Keep-Alive\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)\r\nAccept: /*\r\nContent-Type: application/x-www-form-urlencoded; charset=UTF-8\r\nX-Requested-With: XMLHttpRequest\r\n" + cookies +"\r\n";
          string request3 = "token=" + token + "&amp;aid=" + aid + "&amp;bidReq=" + ptzReq + "&amp;recaptcha_challenge_field=" + rcf + "&amp;recaptcha_response_field=" + rrf+"\r\n\r\n";
          string request2 = "Content-Length: " + (Encoding.UTF8.GetByteCount(request1+request3)+23).ToString() + "\r\n";
          byte[] dataSent = Encoding.UTF8.GetBytes(request1+request2+request3);
          byte[] dataReceived = new byte[10000];
          Socket socket = ConnectSocket(server, 80);
          if (socket == null)
          {
              return null;
          }
          socket.Send(dataSent, dataSent.Length, 0);
          int bytes = 0;
          string page = "";
          do
          {
              bytes = socket.Receive(dataReceived, dataReceived.Length, 0);
              page = page + Encoding.ASCII.GetString(dataReceived, 0, bytes);
          }
          while (bytes &gt; 0);
  
          return page;
  </code></pre>
  
  <p>When I'm trying to receive the webpage Visual Studio says that "Operation on an unblocked socket cannot be completed immediatly", when I add</p>
  
  <pre><code>socket.Blocking = true;
  </code></pre>
  
  <p>My application stops responsing and after ~1 minute it returns page, but it's empty! When I'm trying to make a GET request it works perfect. I hope you will help me. By the way, this is the first time when I use sockets so my code is pretty bad, sorry about that. </p>
  
  <p>*I'm using a ConnectSocket class, which was given as an example at <a href="http://msdn.microsoft.com/ru-ru/library/system.net.sockets.socket.aspx" rel="nofollow">msdn</a> (The link leads to Russian MSDN, sorry, I didn't find the same article in English, but you'll understand the code anyway)</p>