title: C: Sending http get request in linux
body: <p>I'm trying to make a connection localhost on port 80 and send a simple http get request and simultaneously I run wireshark and look at the headers. Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt; 
  #include &lt;sys/socket.h&gt;
  #include &lt;pthread.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  
  
  int main(int argc, char *argv[])
  {
  
    int yes = 1;
   char buffer[1024];
   int newsockfd, portno, recv_length, sockfd;
   socklen_t clilen;
   struct sockaddr_in serv_addr, cli_addr;
   ssize_t number;
   if (sockfd &lt; 0) 
      error("ERROR opening socket");
   bzero((char *) &amp;serv_addr, sizeof(serv_addr));
  
  
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
  
   serv_addr.sin_family = AF_INET;
   serv_addr.sin_addr.s_addr = 0;
   serv_addr.sin_port = htons(80);
  
  
  
  
   connect(sockfd,(struct sockaddr *) &amp;serv_addr,sizeof(serv_addr));
  
  
   if(send(sockfd, 
  
  
   "GET / HTTP/1.1\r\n
   Host: localhost\r\n
   Connection: Keep-alive\r\n
   Cache-Control: max-age=0\r\n
   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,;q=0.8\r\n
   User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36\r\n
   Accept-Encoding: gzip, deflate, sdch\r\n
   Accept-Language: en-US,en;q=0.8\r\n\r\n", 
  
   strlen("GET / HTTP/1.1\r\n
   Host: localhost\r\n
   Connection: Keep-alive\r\n
   Cache-Control: max-age=0\r\n
   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,;q=0.8\r\n
   User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36\r\n
   Accept-Encoding: gzip, deflate, sdch\r\n
   Accept-Language: en-US,en;q=0.8\r\n\r\n"),
  
   0) &gt; 0)
  
   {
      printf("GET send from %d\n", sockfd);
   }
   else
   {
      printf("Problem in send %s\n", strerror(errno));
   }
  </code></pre>
  
  <p>But when I compile it and run it gives me a lot of erros. <a href="http://postimg.org/image/qk3bk8an5/" rel="nofollow">here is the image of errros</a>. After this error I changed the send function to this<br> <strong>send(sockfd, "GET / HTTP/1.1\r\n Host: localhost\r\n\r\n", strlen("GET / HTTP/1.1\r\n Host: localhost\r\n\r\n")</strong> <br>Compilation went ok but the wireshark shows me <em>HTTP/1.0 400 BAD REQUEST (text/html)</em> So I have few questions.<br>
  1)What is the difference between send functions that I've used? I mean does it really matter if I send <br> <strong>GET / HTTP/1.1\r\n Host: localhost\r\n\r\n</strong> <br>or <br><strong>GET / HTTP/1.1\r\n
       Host: localhost\r\n
       Connection: Keep-alive\r\n
       Cache-Control: max-age=0\r\n
       Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,;q=0.8\r\n
       User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36\r\n
       Accept-Encoding: gzip, deflate, sdch\r\n
       Accept-Language: en-US,en;q=0.8\r\n\r\n</strong><br>
  2)How to configure send function to make correct HTTP GET request?
  <br>Hope you can help. Thanks.</p>