title: How to use HTTP GET request using c++ and clean code?
body: <p>I need to connect a c++ console app with a website and retrieve the html page. I use this code:</p>
  
  <pre><code>int main() {
      WSADATA wsaData;
      if (WSAStartup(MAKEWORD(2, 2), &amp;wsaData) != 0) {
          cout &lt;&lt; "WSAStartup failed.\n";
          system("pause");
          return 1;
      }
      SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      struct hostent *host;
      host = gethostbyname("www.giallozafferano.it");
      SOCKADDR_IN SockAddr;
      SockAddr.sin_port = htons(80);
      SockAddr.sin_family = AF_INET;
      SockAddr.sin_addr.s_addr = *((unsigned long*)host-&gt;h_addr);
      cout &lt;&lt; "Connecting...\n";
      if (connect(Socket, (SOCKADDR*)(&amp;SockAddr), sizeof(SockAddr)) != 0) {
          cout &lt;&lt; "Could not connect";
          system("pause");
          return 1;
      }
      cout &lt;&lt; "Connected.\n";
      send(Socket, "GET / HTTP/1.1\r\nHost: www.giallozafferano.it/ricerca-ricette/pasta/\r\nConnection: close\r\n\r\n", strlen("GET / HTTP/1.1\r\nHost: www.giallozafferano.it/ricerca-ricette/pasta/\r\nConnection: close\r\n\r\n"), 0);
      char buffer[10000];
      int nDataLength;
      while ((nDataLength = recv(Socket, buffer, 10000, 0)) &gt; 0) {
          int i = 0;
          while (buffer[i] &gt;= 32 || buffer[i] == '\n' || buffer[i] == '\r') {         
              i += 1;
          }
      }
  
      string page(buffer);
      page = page.erase(page.size()-1);
  
      cout &lt;&lt; endl &lt;&lt; page &lt;&lt; endl;
  
      size_t found = page.find("&lt;Risultati Ricerca");
      if (found != std::string::npos) {
          cout &lt;&lt; "risultati found at position: " &lt;&lt; found &lt;&lt; '\n';
      }
  
      closesocket(Socket);
      WSACleanup();
      system("pause");
      return 0;
  }
  </code></pre>
  
  <p>it works but the result of the site is different every time that I connect to the site... Someone can help me?</p>