Почему при извлечении исходного кода nike.com появляется ошибка «Отказано в доступе»? - PullRequest
0 голосов
/ 27 апреля 2019

Я делаю простую программу, в которой я набираю ссылку, и она получает исходный код этой ссылки.Когда я запускаю его, он отлично работает со ссылками, отличными от определенных ссылок (в частности, ссылок на nike.com).Код показан ниже:

#include <wininet.h>
#include <iostream>
#include <conio.h>
#include <fstream.h>
fstream fs_obj;
using namespace std;

int main(int argc, char *argv[])
{

  fs_obj.open("temp.txt",ios::out | ios::app);  
  HINTERNET hInternet = InternetOpenA("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );

  HINTERNET hConnection = InternetConnectA( hInternet, "https://www.nike.com/t/air-max-97-on-air-jasmine-lasode-shoe-jMqQbs", 80, " "," ", INTERNET_SERVICE_HTTP, 0, 0 ); //enter url here

  HINTERNET hData = HttpOpenRequestA( hConnection, "GET", "/", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );

  char buf[ 2048 ] ;

  HttpSendRequestA( hData, NULL, 0, NULL, 0 ) ;
  string total;
  DWORD bytesRead = 0 ;
  DWORD totalBytesRead = 0 ;

  while( InternetReadFile( hData, buf, 2000, &bytesRead ) && bytesRead != 0 )
  {
    buf[ bytesRead ] = 0 ; // insert the null terminator.
    total=total+buf;
    printf( "%d bytes read\n", bytesRead ) ;

    totalBytesRead += bytesRead ;
  }

  fs_obj<<total<<"\n--------------------end---------------------\n";
  fs_obj.close();
  printf( "\n\n END -- %d bytes read\n", bytesRead ) ;
  printf( "\n\n END -- %d TOTAL bytes read\n", totalBytesRead ) ;

  cout<<endl<<total<<endl; //it will save source code to (temp.txt) file
  InternetCloseHandle( hData ) ;
  InternetCloseHandle( hConnection ) ;
  InternetCloseHandle( hInternet ) ;
  system("pause");
}

Я думал, что он создаст файл с точным исходным кодом, но вместо этого увидел это в temp.txt:

<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>

You don't have permission to access "http&#58;&#47;&#47;www&#46;nike&#46;com&#47;t&#47;air&#45;vapormax&#45;2019&#45;mens&#45;shoe&#45;wr4C0z&#47;AR6631&#45;007" on this server.<P>
Reference&#32;&#35;18&#46;d6fd241&#46;1556374977&#46;d088ca9
</BODY>
</HTML>
...