请教一个问题(关于下载http页面)

Micro_J 2005-03-03 05:37:27
int downloadfile(char*url,char * buffer)
{
HINTERNET hSession;
HINTERNET hConnect;
try
{
hSession = InternetOpen(NULL,
PRE_CONFIG_INTERNET_ACCESS,NULL,NULL,0) ;
if(hSession==NULL) throw(1);
hConnect = InternetOpenUrl(hSession,
url, NULL,0,INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_RELOAD|INTERNET_FLA
G_DONT_CACHE, 0);
if(hConnect==NULL) throw(2);
}catch(...)
{
try
{
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
}catch(...){}
hSession=NULL;
hConnect=NULL;
return -1;
}
int curpos = 0;
char buf[BUFMAX + 4];
try
{
DWORD dwRequest;
DWORD dwRead;
dwRequest = BUFMAX;
while(true)
{
int ReadReturn = InternetReadFile(hConnect,(LPVOID)buf,dwRequest,&dwRead);

if(!ReadReturn)break;
if(dwRead==0)break;
memcpy((char*)buffer + curpos,buf,dwRead);
curpos += dwRead;
}
}catch(...){}
try
{
InternetCloseHandle(hConnect);
InternetCloseHandle(hSession);
}catch(...){}
hSession=NULL;
hConnect=NULL;
return curpos;
}
...全文
75 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Micro_J 2005-03-03
  • 打赏
  • 举报
回复
这是我写的用来下载网页的程序。测试下来速度太慢,在网络正常的情况下平均一张网页要10
秒左右,请教一下各位达人,我的程序问题在哪里?

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧