title: Get HTML of url link with Visual Studio
body: <p>The code below works for the main site, but it does not work for the sub-links. For example, the code works when the url link is "www.reddit.com" or "www.wikipedia.org" but it will not work when it is "www.reddit.com/r/nba" or "www.wikipedia.org/wiki/2007_NASCAR_Nextel_Cup_Series" Do you know how to make it work to include sub-links as well?</p>
  
  <pre><code> #include "stdafx.h"
  #include &lt;winsock2.h&gt;
  #include &lt;WS2tcpip.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  #pragma comment(lib,"ws2_32.lib")
  using namespace std;
  int main(){
      // Initialize Dependencies to the Windows Socket.
      WSADATA wsaData;
      if (WSAStartup(MAKEWORD(2, 2), &amp;wsaData) != 0) {
          cout &lt;&lt; "WSAStartup failed.\n";
          system("pause");
          return -1;
      }
  
      // We first prepare some "hints" for the "getaddrinfo" function
      // to tell it, that we are looking for a IPv4 TCP Connection.
      struct addrinfo hints;
      ZeroMemory(&amp;hints, sizeof(hints));
      hints.ai_family = AF_INET;          // We are targeting IPv4
      hints.ai_protocol = IPPROTO_TCP;    // We are targeting TCP
      hints.ai_socktype = SOCK_STREAM;    // We are targeting TCP so its SOCK_STREAM
  
      // Aquiring of the IPv4 address of a host using the newer
      // "getaddrinfo" function which outdated "gethostbyname".
      // It will search for IPv4 addresses using the TCP-Protocol.
      struct addrinfo* targetAdressInfo = NULL;
      DWORD getAddrRes = getaddrinfo("www.wikipedia.org/wiki/2007_NASCAR_Nextel_Cup_Series", NULL, &amp;hints, &amp;targetAdressInfo);
      if (getAddrRes != 0 || targetAdressInfo == NULL)
      {
          cout &lt;&lt; "Could not resolve the Host Name" &lt;&lt; endl;
          system("pause");
          WSACleanup();
          return -1;
      }
  
      // Create the Socket Address Informations, using IPv4
      // We dont have to take care of sin_zero, it is only used to extend the length of SOCKADDR_IN to the size of SOCKADDR
      SOCKADDR_IN sockAddr;
      sockAddr.sin_addr = ((struct sockaddr_in*) targetAdressInfo-&gt;ai_addr)-&gt;sin_addr;    // The IPv4 Address from the Address Resolution Result
      sockAddr.sin_family = AF_INET;  // IPv4
      sockAddr.sin_port = htons(80);  // HTTP Port: 80
  
      // We have to free the Address-Information from getaddrinfo again
      freeaddrinfo(targetAdressInfo);
  
      // Creation of a socket for the communication with the Web Server,
      // using IPv4 and the TCP-Protocol
      SOCKET webSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if (webSocket == INVALID_SOCKET)
      {
          cout &lt;&lt; "Creation of the Socket Failed" &lt;&lt; endl;
          system("pause");
          WSACleanup();
          return -1;
      }
  
      // Establishing a connection to the web Socket
      cout &lt;&lt; "Connecting...\n";
      if (connect(webSocket, (SOCKADDR*)&amp;sockAddr, sizeof(sockAddr)) != 0)
      {
          cout &lt;&lt; "Could not connect";
          system("pause");
          closesocket(webSocket);
          WSACleanup();
          return -1;
      }
      cout &lt;&lt; "Connected.\n";
  
      // Sending a HTTP-GET-Request to the Web Server
      const char* httpRequest = "GET / HTTP/1.1\r\nHost: www.google.com\r\nConnection: close\r\n\r\n";
      int sentBytes = send(webSocket, httpRequest, strlen(httpRequest), 0);
      if (sentBytes &lt; strlen(httpRequest) || sentBytes == SOCKET_ERROR)
      {
          cout &lt;&lt; "Could not send the request to the Server" &lt;&lt; endl;
          system("pause");
          closesocket(webSocket);
          WSACleanup();
          return -1;
      }
  
      // Receiving and Displaying an answer from the Web Server
      char buffer[10000];
      ZeroMemory(buffer, sizeof(buffer));
      int dataLen;
      while ((dataLen = recv(webSocket, buffer, sizeof(buffer), 0) &gt; 0))
      {
          int i = 0;
          while (buffer[i] &gt;= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
              cout &lt;&lt; buffer[i];
              i += 1;
          }
      }
  
      // Cleaning up Windows Socket Dependencies
      closesocket(webSocket);
      WSACleanup();
  
      system("pause");
      return 0;
  }
  </code></pre>