<code>CString strVerb;
if
( bHead ) strVerb = _T(
"HEAD "
);
else
strVerb = _T(
"GET "
);
CString strSend,strHeader,strRange;
int iStatus = 0, nRet;
char szReadBuf[1025];
DWORD dwContentLength,dwStatusCode;
while
(TRUE)
{
if
(m_pSocket.m_hSocket != NULL)
m_pSocket.Close();
m_pSocket.Create();
m_pSocket.Connect(m_strServer, m_nPort);
strSend = strVerb + m_strObject +
" HTTP/1.1\r\n"
;
strSend +=
"Host: "
+ m_strServer +
"\r\n"
;
strSend +=
"Accept: */*\r\n"
;
strSend +=
"Pragma: no-cache\r\n"
;
strSend +=
"Cache-Control: no-cache\r\n"
;
if
( !m_strReferer.IsEmpty() )
strSend +=
"Referer: "
+ m_strReferer +
"\r\n"
;
strSend +=
"Connection: close\r\n"
;
strRange =
"Range: bytes=100-\r\n"
;
strSend += strRange;
strSend +=
"\r\n"
;
int ret = m_pSocket.Send(strSend.GetBuffer(0), strSend.GetLength());
strSend.ReleaseBuffer();
strHeader.
Empty
();
while
( TRUE )
{
ZeroMemory(szReadBuf,1025);
ret = m_pSocket.Receive(szReadBuf, 1025);
if
( szReadBuf[0] ==
'\0'
)
break
;
strHeader += szReadBuf;
if
( iStatus == 0)
strHeader +=
"\r\n"
;
}
nRet = GetInfo(strHeader,dwContentLength,dwStatusCode,m_TimeLastModified);
switch
( nRet )
{
case
HTTP_FAIL:
return
SENDREQUEST_FAIL;
break
;
case
HTTP_ERROR:
return
SENDREQUEST_ERROR;
break
;
case
HTTP_REDIRECT:
continue
;
break
;
case
HTTP_OK:
m_dwDownloadSize = dwContentLength + 100;
if
( strRange.IsEmpty() )
m_dwFileSize = dwContentLength + 100;
else
{
if
( dwStatusCode == 206 )
{
m_bSupportResume = TRUE;
m_dwFileSize = dwContentLength + 100;
}
else
{
m_bSupportResume = FALSE;
m_dwFileSize = dwContentLength + 100;
}
}
return
SENDREQUEST_SUCCESS;
break
;
default
:
return
SENDREQUEST_FAIL;
break
;
}
}
m_pSocket.Close();
return
SENDREQUEST_SUCCESS;</code>