title: Send Http "Post" Request To Php Code in C or C++
body: <p>I'm trying to send a "post" reguest to my php file and get the info back, it works fine, but </p>
  
  <p>it also print something before printing my response from the php file. this is what it print </p>
  
  <p>first:</p>
  
  <pre>
  HTTP/1.1 200 OK
  Date: Fri, 20 Apr 2012 10:19:12 GMT
  Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
  X-Powered-By: PHP/5.3.6
  Content-Length: 12
  Connection: close
  Content-Type: text/html
  </pre>
  
  <p>and then my response:</p>
  
  <pre>
  hello world
  </pre>
  
  <p>how can i only print what i'm getting from myphp code, without: </p>
  
  <pre>
  HTTP/1.1 200 OK
  Date: Fri, 20 Apr 2012 10:19:12 GMT
  Server: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/0.9.8r DAV/2 PHP/5.3.6
  X-Powered-By: PHP/5.3.6
  Content-Length: 12
  Connection: close
  Content-Type: text/html
  </pre>
  
  <p>the code i'm using is:</p>
  
  <pre><code>#include &lt;arpa/inet.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;unistd.h&gt;
  
  #define SA      struct sockaddr
  #define MAXLINE 4096
  #define MAXSUB  200
  
  
  #define LISTENQ         1024
  
  extern int h_errno;
  
  
  ssize_t process_http(int sockfd, char *host, char *page, char *poststr)
  {
       char sendline[MAXLINE + 1], recvline[MAXLINE + 1];
      ssize_t n;
      snprintf(sendline, MAXSUB,
               "POST %s HTTP/1.0\r\n"
               "Host: %s\r\n"
               "Content-type: application/x-www-form-urlencoded\r\n"
               "Content-length: %d\r\n\r\n"
               "%s", page, host, strlen(poststr), poststr);
  
      write(sockfd, sendline, strlen(sendline));
      while ((n = read(sockfd, recvline, MAXLINE)) &gt; 0) {
          recvline[n] = '\0';
          printf("%s", recvline);  // &lt;-- this
      }
      return n;
  
  }
  
  
  
  
  
  int main(void)
  {
  
  
  
      int sockfd;
      struct sockaddr_in servaddr;
  
      char **pptr;
      //********** You can change. Puy any values here *******
      char *hname = "localhost";
      char *page = "/mysql_update.php";
      char *poststr = "server=dd sd sdsdt\n";
      //*******************************************************
  
      char str[50];
      struct hostent *hptr;
      if ((hptr = gethostbyname(hname)) == NULL) {
          fprintf(stderr, " Server down error for host: %s: %s",
                  hname, hstrerror(h_errno));
          exit(1);
      }
      printf("hostname: %s \n", hptr-&gt;h_name);
      if (hptr-&gt;h_addrtype == AF_INET
          &amp;&amp; (pptr = hptr-&gt;h_addr_list) != NULL) {
          printf("address: %s\n",
                 inet_ntop(hptr-&gt;h_addrtype, *pptr, str,
                           sizeof(str)));
      } else {
          fprintf(stderr, "Error call inet_ntop \n");
      }
  
      sockfd = socket(AF_INET, SOCK_STREAM, 0);
      bzero(&amp;servaddr, sizeof(servaddr));
      servaddr.sin_family = AF_INET;
      servaddr.sin_port = htons(80);
      inet_pton(AF_INET, str, &amp;servaddr.sin_addr);
  
      connect(sockfd, (SA *) &amp; servaddr, sizeof(servaddr));
      process_http(sockfd, hname, page, poststr);
      close(sockfd);
      exit(0);
  
  
  }
  </code></pre>
  
  <p>Please help me to fix this problem, step by step so' i can understand it, give me information and please if you can' show me a example. ( this will help me and others ) </p>