title: HTTP request to Wikipedia
body: <p>I am trying to access a Wikipedia page via socket programming and a C++ script. I am able to reach the server, but get a 404 error informing me that the requested URL does not exist. Just entering the same URL in a browser works fine.</p>
  
  <p>This is the URL: <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" rel="nofollow">http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol</a></p>
  
  <p>This is the C++ script:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;resolv.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  int main()
  {
      int s, error;
      char length[10];
      length[0]=0;    
  
      struct sockaddr_in addr;
  
      if((s = socket(AF_INET,SOCK_STREAM,0))&lt;0)
      {
          cout&lt;&lt;"Error 01: creating socket failed!\n";
          close(s);
          return 1;
      }
  
      addr.sin_family = AF_INET;
      addr.sin_port = htons(80);
      inet_aton("204.27.61.92",&amp;addr.sin_addr);
  
      error = connect(s,(sockaddr*)&amp;addr,sizeof(addr));
      if(error!=0)
      {
          cout&lt;&lt;"Error 02: conecting to server failed!\n";
          close(s);
          return 1;
      }
  
      char msg[]="GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\nHOST: en.wikipedia.org\n\n"
  
      int leng = send(s, msg, sizeof(msg), 0);
  
      if(leng == -1)
           cout&lt;&lt;"There is a problem!"&lt;&lt;endl;
  
      send(s,msg,sizeof(msg),0);
  
      char answ[1024];
  
      ssize_t len;
      while((len = recv(s, answ, 1024, 0)) &gt; 0)
      {
          cout.write(answ, len);
      }
      cout &lt;&lt; endl;
  
      if(len &lt; 0)
      {
          cout&lt;&lt;"Error!"&lt;&lt;endl;
      }
  
      close(s);
  
      return 0;
  }
  </code></pre>
  
  <p>The script works fine overall. Exchanging the line </p>
  
  <pre><code>char msg[]="GET /wiki/Hypertext_Transfer_Protocol HTTP/1.1\nHOST: en.wikipedia.org\n\n";
  </code></pre>
  
  <p>with</p>
  
  <pre><code>char msg[] = "GET /beej/inet_ntoaman.html http/1.1\nHOST: retran.com\n\n";
  </code></pre>
  
  <p>retrieves the requested web site without error. What am I missing here? Why does the script not work for Wikipedia?</p>
  
  <p>Thanks</p>