用Socket下载HTML网页,为何文件没有下载完呀,高手给看看!代码是。。。
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();
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();
...全文
相关推荐
家具材料与家具总论.pdf
家具材料与家具总论.pdf
Android之浏览器作为客户端访问手机socket作为服务端下载图片和网页和APK
1 需求 在同一局域网内,手机(PC端)浏览器作为客户端,然后手机app里面通过socket写服务代码,然后浏览器访问手机服务端访问网页和图片和css文件和下载APK 2 代码实现 创建服务线程代码 var serverSocket: ServerSocket? = null var run = true inner class HttpServerThread : Runnable { var TAG = javaClass.na...
家具材料分类认识.pdf
家具材料分类认识.pdf
史上最全的家具材料分类说明.pdf
史上最全的家具材料分类说明.pdf
家具考试题汇总.pdf
家具考试题汇总.pdf


网络编程
