title: PHP fsockopen 400 Bad Request
body: <p>I have this strange problem that I'm receiving 400 Bad request as a response and I have absolutely no idea what's wrong with the header. Here's my code:</p>
  
  <pre><code>&lt;?php
  
  $sock = fsockopen('IP ADDRESS', 80, $errno, $errstr);
  
  $header = array(
      'GET / HTTP/1.1',
      'Host: stackoverflow.com',
      'User-agent: My Useragent',
      'Connection: Close'
  );
  
  fputs($sock, join('\r\n', $header));
  
  while(!feof($sock))
  {
      echo fgets($sock, 128);
      break;
  }
  
  fclose($sock);
  
  ?&gt;
  </code></pre>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT</strong>: Thanks to MrCode this problem was solved. Issue was here:</p>
  
  <pre><code>fputs($sock, join('\r\n', $header));
  </code></pre>
  
  <p>I had to change it to:</p>
  
  <pre><code>fputs($sock, join("\r\n", $header)."\r\n\r\n");
  </code></pre>
  
  <p><strong>Notice double quotes and "\r\n\r\n"</strong></p>
  
  <p>Thanks again to MrCode</p>