用Socket下载HTML网页,为何文件没有下载完呀,高手给看看!代码是。。。

wang_bluebird wang_bluebird 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
CSocket sock;
sock.Create();
sock.Connect(m_url,80);
CString str;
str="GET / HTTP/1.1\r\n";
str+="Accept: image//gif, image//x-xbitmap, image//jpeg, image//pjpeg, application//x-shockwave-flash, application//vnd.ms-excel, application//vnd.ms-powerpoint, application//msword, *//*\r\n";
str+="Accept-Language: zh-cn\r\n";
str+="Accept-Encoding: gzip, deflate\r\n";
str+="User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)\r\n";
str+="Host:";
str+=m_url;
str+="\r\n";
str+="Connection: Keep-Alive\r\n\r\n";
sock.Send(str,str.GetLength(),0);
m_post=str;

CFile fp;
fp.Open("c:\\test.htm",CFile::modeCreate|CFile::modeWrite);
DWORD len=0;
char buf[4096];
memset(buf,0,4096);
len=sock.Receive(buf,4096);
fp.Write(buf,4096);
while(len>=4096)
{

memset(buf,0,4096);
len=sock.Receive(buf,4096);
fp.Write(buf,4096);
}
sock.Close();
fp.Close();
WSACleanup();
...全文
评论 4
收藏 已收藏
分享
返回顶部
wang_bluebird
网络编程 18,356 成员 64,161 内容