我仍然在从网络上保存随机的网页。在对代码稍作修改(以不同的方式调用HttpOpenRequest() )之后,程序成功下载了一个被重定向的页面。但是我还是不能得到我想要的任何网页。
示例:
#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/",我失败了,也就是说,程序运行了不到一秒钟,并且没有产生任何输出文件。
这里的问题是什么,是什么函数导致了这种情况的发生?
发布于 2011-11-30 17:08:00
尝试从示例URL中删除"http://“”。
Connection = InternetConnect(Initialize,"www.rottentomatoes.com", INTERNET_DEFAULT_HTTP_PORT,
NULL,NULL,INTERNET_SERVICE_HTTP,0,0);
并确保HttpOpenRequest中的文件名有效。
https://stackoverflow.com/questions/8284615
复制相似问题