if(!bReturn)
{
message="发送请求失败";
return 0;
}
///第6行:连接设置,保持
// SocketSend(HTTPSocket,"Connection:Keep-Alive\r\n");
///第7行:Cookie.
bReturn=SocketSend(HTTPSocket,"Cache-Control: no-cache\r\n");
if(!bReturn)
{
message="发送请求失败";
return 0;
}
bReturn=SocketSend(HTTPSocket,"Proxy-Connection: Keep-Alive\r\n");
if(!bReturn)
{
message="发送请求失败";
return 0;
}
/// 续传
Range是要下载的数据范围,对续传很重要
if(continueFlag)
{
temp.Format("Range: bytes=%d- \r\n",conLength);
bReturn=SocketSend(HTTPSocket,temp);
if(!bReturn)
{
message="发送请求失败";
return 0;
}
}
///最后一行:空行
bReturn=SocketSend(HTTPSocket,"\r\n");
if(!bReturn)
{
message="发送请求失败";
return 0;
}
///取得http头
int i;
i=GetHttpHeader(HTTPSocket,tmpBuffer);
if(!i)
{
message="获取HTTP头出错";
return 0;
}
//如果取得的http头含有404等字样,则表示连接出问题
temp=tmpBuffer;
if(temp.Find("404")!=-1)
{
return 0;
}
// 得到待下载文件的大小
filelength=GetFileLength(tmpBuffer);
return 1;
}
这样,就连接到网上的另一台机了,如何下载数据,不用多说了吧
while((num!=SOCKET_ERROR) && (num!=0))
{
num=recv (HTTPSocket
,(char FAR *)tmpBuffer
,(MAXBLOCKSIZE-1)
,0);
file.Write(tmpBuffer,num);
if(ExitFlag)
{
file.Close();
closesocket(HTTPSocket);
DownComplete=1;
m_message.CleanText();
m_message.ShowColorText(RGB(128,128,0),DLCompleteMes);
m_progress.ShowWindow(SW_HIDE);
m_stopDownload.ShowWindow(SW_HIDE);
_endthread();
}
}
基本就是这样了,本人写程序水平也不是很高,这个程序还是可以用的。



