ImageVerifierCode 换一换
格式:DOC , 页数:17 ,大小:55.50KB ,
资源ID:12012048      下载积分:10 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/12012048.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(HTTP服务器上断点下载文件.doc)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

HTTP服务器上断点下载文件.doc

1、HTTP服务器上断点下载文件  从HTTP服务器上下载一个文件有很多方法,“热心”的微软提供了 WinInet 类,用起来也很方便。当然,我们也可以自己实现这些功能,通过格式化请求头很容易就能实现断点续传和检查更新等等功能 。 1. 连接主机 2. 格式化请求头 3. 设置接收,发送超时             要想从服务器下载文件,首先要向服务器发送一个请求。HTTP 请求头由若干行字符串组成。下面结合实例说说 HTTP 请求头的格式。假设要下载 这个网页 ,那么请求头的写法如下: 第1行:方法,请求的内容,HTTP协议的版本 下载一般可以用GET方法,请求

2、的内容是“/index.html”,HTTP协议的版本是指浏览器支持的版本,对于下载软件来说无所谓,所以用1.1版 “HTTP/1.1”; “GET /index.html HTTP/1.1” 第2行:主机名,格式为“Host:主机” 在这个例子中是:“Host:” 第3行:接受的数据类型,下载软件当然要接收所有的数据类型,所以: “Accept:*/*” 第4行:指定浏览器的类型 有些服务器会根据客户服务器种类的不同会增加或减少一些内容,在这个例子中可以这样写: “User-Agent:Mozilla/4.0 (compatible; MSIE 5.00; Win

3、dows 98)” 第5行:连接设置 设定为一直保持连接:“Connection:Keep-Alive” 第6行:若要实现断点续传则要指定从什么位置起接收数据,格式如下: “Range: bytes=起始位置 - 终止位置” 比如要读前500个字节可以这样写:“Range: bytes=0 - 499”;从第 1000 个字节起开始下载: “Range: bytes=999 -” 最后,别忘了加上一行空行,表示请求头结束。整个请求头如下: GET /index.html HTTP/1.1 Host: Accept:*/* User-Agent:Mozilla/4.0

4、compatible; MSIE 5.00; Windows 98) Connection:Keep-Alive 下面用例子看看如何进行断点的下载吧 // DownloadFile.h: interface for the CDownloadFile class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_DOWNLOADFILE_H__E9A59779_BEF9_4A78_8D0E_ED8C9498E07C__INC

5、LUDED_) #define AFX_DOWNLOADFILE_H__E9A59779_BEF9_4A78_8D0E_ED8C9498E07C__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define NOTIFY_MSG_WPARAM_GENDOWNFILEID                0x01 #define NOTIFY_MSG_LOW_WPARAM_FULLSIZE                0x10 #define NOTIFY_MSG_LOW_WP

6、ARAM_CURRENTSIZE            0x20 #define NOTIFY_MSG_LOW_WPARAM_DOWNSIZE                0x30 #define NOTIFY_MSG_LOW_WPARAM_DOWNSPEED                0x40 class CDownloadFile   { public:     BOOL OpenRedirectHttpURL(CString &strOldLocation,CInternetSession &cSession);     BOOL DownLoadFile(LPC

7、TSTR lpFileURL,LPCTSTR lpSaveFile);     CDownloadFile();     virtual ~CDownloadFile();     LPCTSTR GetSavedFileName() { return m_strSaveToFile;}     LPCTSTR GetDownURL() { return m_strFileURL;} public:     WORD GenFileID();     void RegisterNotifyWindow(DWORD dwThreadID,HWND hWnd,DWORD dwMs

8、g);     BOOL GetUNCFile();     bool m_bForceReload;`     DWORD m_TimeOut;     WORD m_wFileID; protected:     DWORD m_dwThreadID;     void PostNotifyMessage(WPARAM wParam, LPARAM lParam);     DWORD m_dwMsgID;     HWND m_hNotify;     BOOL GetFtpFile(CInternetSession &cSession);     BOOL G

9、etHttpFile(CInternetSession &cSession);     CString m_strTmpFileName;     CString m_strFileURL;     CString m_strSaveToFile;     CString    m_rawHeaders;     float  m_transferRate;     DWORD    m_infoStatusCode; }; #endif // !defined(AFX_DOWNLOADFILE_H__E9A59779_BEF9_4A78_8D0E_ED8C9498E07C

10、INCLUDED_) // DownloadFile.cpp: implementation of the CDownloadFile class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "DownloadFile.h" #pragma comment( lib,"Wininet.lib" ) #include "shlwapi.h" #pragma comment( lib,"shlwapi

11、lib" ) #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif #define BUFFER_SIZE 4095 const TCHAR szHeaders[] = _T("Accept: */*\r\nUser-Agent:  Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\r\n"); ////////////////////////////////////////////

12、////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CDownloadFile::CDownloadFile() {     m_TimeOut = 0;     m_bForceReload = true;     m_dwThreadID = 0;     m_hNotify = NULL;     m_dwMsgID = 0;     m_wFileID = 0;

13、} CDownloadFile::~CDownloadFile() { } BOOL CDownloadFile::DownLoadFile(LPCTSTR lpFileURL, LPCTSTR lpSaveFile) {     BOOL bRet = FALSE;     if ( !::PathIsURL(lpFileURL) )     {         return bRet;     }     m_strSaveToFile = lpSaveFile;     m_strFileURL = lpFileURL;     m_strTmpFi

14、leName = lpSaveFile;     m_strTmpFileName += _T(".df!");     CString strServer,strObject;INTERNET_PORT nPort;     CString strAgentCaption =  _T("Update Download ") ;     strAgentCaption += ::PathFindFileName(lpSaveFile);     DWORD dwFlags = 0;     InternetGetConnectedState(&dwFlags, 0);     C

15、InternetSession session (strAgentCaption, 1,         (dwFlags & INTERNET_CONNECTION_PROXY) == INTERNET_CONNECTION_PROXY ? INTERNET_OPEN_TYPE_PRECONFIG : INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY,         NULL, NULL, 0);     AfxParseURL(m_strFileURL,dwFlags,strServer,strObject,nPort);     

16、if (m_TimeOut != 0)         session.SetOption(INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, m_TimeOut);     if( !m_wFileID )         m_wFileID = GenFileID();     PostNotifyMessage(NOTIFY_MSG_WPARAM_GENDOWNFILEID,m_wFileID);     try     {         if ( dwFlags== AFX_INET_SERVICE_HTTP )         {   

17、          bRet = GetHttpFile(session);         }         else if( dwFlags== AFX_INET_SERVICE_FTP )         {             bRet = GetFtpFile(session);         }         else if( dwFlags== AFX_INET_SERVICE_FILE )         {             if( UrlIsFileUrl(m_strFileURL) )                 bRet = Get

18、UNCFile();         }         else         {             ;         }         }     catch (CException* pEx)     {         TCHAR szErrorMsg[MAX_PATH] = {0};         pEx->GetErrorMessage(szErrorMsg, MAX_PATH);         TRACE( _T("Exception: %s\n") , szErrorMsg);         pEx->Delete();     }

19、     session.Close();     m_wFileID = 0;     if (bRet)     {         if (!::MoveFileEx(m_strTmpFileName,m_strSaveToFile,MOVEFILE_REPLACE_EXISTING) )         {             Sleep(1000);             ::MoveFileEx(m_strTmpFileName,m_strSaveToFile,MOVEFILE_REPLACE_EXISTING);         }     }   

20、  return bRet; } BOOL CDownloadFile::GetHttpFile(CInternetSession &cSession) {     BOOL bRet = FALSE;     CFile m_TmpFile;     CFileException fileException;          if ( !m_TmpFile.Open (m_strTmpFileName,          CFile::modeCreate | CFile::modeNoTruncate  | CFile::modeReadWrite        

21、 | CFile::shareDenyWrite    | CFile::typeBinary,         &fileException ) )     {         TRACE( _T("Open File failed: %d\n"), fileException.m_cause );         return bRet;     }     CString strRangeQuest;     if (m_TmpFile.GetLength()>0)     {         PostNotifyMessage(MAKEWPARAM(NOTIFY_

22、MSG_LOW_WPARAM_CURRENTSIZE,m_wFileID),m_TmpFile.GetLength());         m_TmpFile.SeekToEnd();         strRangeQuest.Format( _T("%sRange: bytes=%d-\r\n"), szHeaders,m_TmpFile.GetLength());     }     else         strRangeQuest = szHeaders;     DWORD dwCount = 0;     CHttpFile* pFile = NULL;  

23、   CString strTmpURL = m_strFileURL;     try     {         DWORD dwFlags = INTERNET_FLAG_TRANSFER_BINARY              |INTERNET_FLAG_DONT_CACHE             |INTERNET_FLAG_PRAGMA_NOCACHE             ;         if (m_bForceReload) {             dwFlags |= INTERNET_FLAG_RELOAD;         }      

24、   //Here Find URLFile Redirect. //        OpenRedirectHttpURL(strTmpURL,cSession);         pFile = (CHttpFile*) cSession.OpenURL(strTmpURL, 1, dwFlags,strRangeQuest, -1);     }     catch (CInternetException* e)     {         TCHAR   szCause[MAX_PATH] = {0};         e->GetErrorMessage(szCause

25、 MAX_PATH);         e->Delete();         delete pFile;         pFile = NULL;         return bRet;     }          COleDateTime startTime = COleDateTime::GetCurrentTime();     DWORD dwHttpFileSize = 0;     if (pFile)     {         BYTE buffer[BUFFER_SIZE+1] = {0};         try {          

26、   UINT nRead = 0;             pFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,dwHttpFileSize);             PostNotifyMessage(MAKEWPARAM(NOTIFY_MSG_LOW_WPARAM_FULLSIZE,m_wFileID),dwHttpFileSize);             TRACE( _T("Totoal Length is %d\n"), dwHttpFileSize );             dw

27、Count = 0;             do             {                 nRead = pFile->Read(buffer, BUFFER_SIZE);                 if (nRead > 0)                 {                     buffer[nRead] = 0;                     m_TmpFile.Write(buffer,nRead);                                          COleDateTimeS

28、pan elapsed = COleDateTime::GetCurrentTime() - startTime;                     double dSecs = elapsed.GetTotalSeconds();                     PostNotifyMessage(MAKEWPARAM(NOTIFY_MSG_LOW_WPARAM_DOWNSIZE,m_wFileID),dwCount);                     if (dSecs > 0.0)                     {                

29、         dwCount += nRead;                         m_transferRate = (float) ( dwCount / 1024.0 / dSecs );                         TRACE("Read %d bytes (%0.1f Kb/s)\n", dwCount, m_transferRate );                     }                     else                     {                         TRACE(

30、"Read %d bytes\n", dwCount);                         m_transferRate = (float) ( dwCount / 1024.0 );                     }                     PostNotifyMessage(MAKEWPARAM(NOTIFY_MSG_LOW_WPARAM_DOWNSPEED,m_wFileID),(LPARAM)m_transferRate);                 }             }             while (nRea

31、d > 0);             bRet = TRUE;         }         catch (CFileException *e)         {             TCHAR   szCause[MAX_PATH] = {0};             e->GetErrorMessage(szCause, MAX_PATH);             TRACE("ErrorMsg : %s\n", szCause);             e->Delete();             delete pFile;          

32、   m_TmpFile.Close();             return FALSE;         }         pFile->QueryInfoStatusCode(m_infoStatusCode);                pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS ,m_rawHeaders);         pFile->Close();         m_TmpFile.Close();         delete pFile;     }          return bRet; }

33、BOOL CDownloadFile::OpenRedirectHttpURL(CString &strOldLocation,CInternetSession &cSession) {     BOOL bRet = FALSE;     CHttpFile *pFile = NULL;     CHttpConnection* pServer = NULL;     CString strServerName,strObject;     INTERNET_PORT nPort = 0;     DWORD dwServiceType = 0;          if (

34、AfxParseURL(strOldLocation, dwServiceType, strServerName, strObject, nPort) ||         dwServiceType != INTERNET_SERVICE_HTTP)     {         TRACE( _T("Not A Http Quest!\n") );         return bRet;     }          pServer = cSession.GetHttpConnection(strServerName, nPort);          pFile = 

35、pServer->OpenRequest(CHttpConnection::HTTP_VERB_GET,         strObject, NULL, 1, NULL, NULL,          INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_AUTO_REDIRECT);     pFile->AddRequestHeaders(szHeaders);     pFile->SendRequest();          DWORD dwRet;     pFile->QueryInfoStatusCode(dwRet

36、);          // if access was denied, prompt the user for the password          if (dwRet == HTTP_STATUS_DENIED)     {         DWORD dwPrompt;         dwPrompt = pFile->ErrorDlg(NULL, ERROR_INTERNET_INCORRECT_PASSWORD,             FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHAN

37、GE_OPTIONS, NULL);                  // if the user cancelled the dialog, bail out                  if (dwPrompt != ERROR_INTERNET_FORCE_RETRY)         {             TRACE( _T("Access denied: Invalid password\n") );             // close up the redirected site             pFile->Close();   

38、          delete pFile;             pServer->Close();             delete pServer;             return bRet;         }                  pFile->SendRequest();         pFile->QueryInfoStatusCode(dwRet);     }              // were we redirected?     // these response status codes come from W

39、ININET.H          if (dwRet == HTTP_STATUS_MOVED ||         dwRet == HTTP_STATUS_REDIRECT ||         dwRet == HTTP_STATUS_REDIRECT_METHOD)     {         CString strNewLocation;         pFile->QueryInfo(HTTP_QUERY_RAW_HEADERS_CRLF, strNewLocation);         int nPlace = strNewLocation.Find(_T(

40、"Location: "));         if (nPlace == -1)         {             TRACE( _T("Error: Site redirects with no new location\n") );             // close up the redirected site             pFile->Close();             delete pFile;             pServer->Close();             delete pServer;         

41、    return bRet;         }             strNewLocation = strNewLocation.Mid(nPlace + 10);         nPlace = strNewLocation.Find('\n');         if (nPlace > 0)             strNewLocation = strNewLocation.Left(nPlace);         strOldLocation = strNewLocation;     }     if ( dwRet == HTTP_STATUS_

42、OK )     {         bRet = TRUE;     }     // close up the redirected site     pFile->Close();     delete pFile;     pServer->Close();     delete pServer;     return bRet; } BOOL CDownloadFile::GetFtpFile(CInternetSession &cSession) {     BOOL bRet = FALSE;     CFile m_TmpFile;    

43、 CFileException fileException;          if ( !m_TmpFile.Open (m_strTmpFileName,          CFile::modeCreate | CFile::modeNoTruncate  | CFile::modeReadWrite         | CFile::shareDenyWrite    | CFile::typeBinary,         &fileException ) )     {         TRACE( _T("Open File failed: %d\n"), file

44、Exception.m_cause );         return bRet;     }     DWORD dwCount = 0;     CFtpConnection *pFtpConn = NULL;     CInternetFile *pFile = NULL;     try     {         CString strServerName,strObject,strUserName,strPassword;         INTERNET_PORT nPort = 0;         DWORD dwServiceType = 0;  

45、       CString strRestPointCommand;              if (!AfxParseURLEx(m_strFileURL, dwServiceType, strServerName, strObject, nPort,              strUserName, strPassword) ||             dwServiceType != INTERNET_SERVICE_FTP)         {             TRACE( _T("Not A Ftp Quest!\n") );         }   

46、      // CFtpConnection ERROR_INTERNET_NO_DIRECT_ACCESS CInternetSession         if (strUserName.IsEmpty())             pFtpConn = cSession.GetFtpConnection(strServerName,NULL,NULL,nPort,m_bForceReload);         else             pFtpConn = cSession.GetFtpConnection(strServerName,strUserName,strP

47、assword,nPort,m_bForceReload);         if (m_TmpFile.GetLength())         {             PostNotifyMessage(MAKEWPARAM(NOTIFY_MSG_LOW_WPARAM_CURRENTSIZE,m_wFileID),m_TmpFile.GetLength());             m_TmpFile.SeekToEnd();             strRestPointCommand.Format( _T("REST %d"), m_TmpFile.GetLength

48、));             //strRestPointCommand.Format( _T("ls") );             if ( !FtpCommand((*pFtpConn), FALSE, FTP_TRANSFER_TYPE_ASCII,              strRestPointCommand, 0, 0) )             {                 TRACE( _T("FtpCommand failed, error: %d\n"), GetLastError());                 m_TmpFile.S

49、eekToBegin();             }             }         if (pFtpConn)         {             pFile = pFtpConn->OpenFile(strObject);         }     }     catch (CInternetException* e)     {         TCHAR   szCause[MAX_PATH] = {0};         e->GetErrorMessage(szCause, MAX_PATH);         e->Delete();         delete pFile;         delete pFtpConn;         return bRet;     }          COleDateTime startTime = COleDateTime::GetCurrentTime();     DWORD dwFtpFileSize = 0;     if (pFile)     {         BYTE buffer[BUFFER_SIZE+1] 

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服