2
我仍然在保存隨機網頁的網頁。對代碼稍作修改(以不同方式調用HttpOpenRequest())後,程序成功下載了正在重定向的頁面。但我仍然無法獲得我想要的任何網頁。Hep on HttpOpenRequest()和其他Wininet函數
例子:
#include <windows.h>
#include <wininet.h>
#include <stdio.h>
#include <fstream>
#include <cstring>
#define SIZE 128
int main()
{
HINTERNET Initialize,Connection,File;
DWORD dwBytes;
char ch;
Initialize = InternetOpen("HTTPGET",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,0);
Connection = InternetConnect(Initialize,"http://www.rottentomatoes.com",INTERNET_DEFAULT_HTTP_PORT,
NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
//File = HttpOpenRequest(Connection,NULL,"/index.html",NULL,NULL,NULL,0,0);
/**/
File = HttpOpenRequest(Connection,
"GET",
"/index.jsp",
"HTTP/1.1",
NULL, NULL,
INTERNET_FLAG_RELOAD | INTERNET_FLAG_EXISTING_CONNECT, 0);
if(HttpSendRequest(File,NULL,0,NULL,0))
{
std::ofstream webSource;
//webSource.open(strcat(argv[1], "__.html"));
webSource.open("a.html");
while(InternetReadFile(File,&ch,1,&dwBytes))
{
if(dwBytes != 1)break;
webSource << ch;
}
webSource.close();
}
InternetCloseHandle(File);
InternetCloseHandle(Connection);
InternetCloseHandle(Initialize);
return 0;
}
但是,當我嘗試下載「http://www.rottentomatoes.com/m/1209933-puss_in_boots/」,我失敗了,那就是,程序不到運行一秒鐘,並不產生輸出文件。
這裏有什麼問題,是什麼原因導致了這種情況發生?