用InternetOpen()的下载文件
#include<windows.h> #include<wininet.h> #include<iostream> using namespace std; #pragma comment(lib,"wininet.lib") void main() { DWORD byteread=0; char buffer[100]; memset(buffer,0,100); HINTERNET internetopen; internetopen=InternetOpen("Testing",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0); if (internetopen==NULL){ cout<<"Internet open failed!"<<endl; return;} HINTERNET internetopenurl; internetopenurl=InternetOpenUrl(internetopen,"http://package6.kuaiapp.cn/201407/26/6002_887171753_1.0.0_5.0.ipa",NULL,0,INTERNET_FLAG_RELOAD,0); if (internetopenurl==NULL){ cout<<"Internet open url failed!"<<endl; goto there;} BOOL hwrite = 0; DWORD written = 0; HANDLE createfile; createfile=CreateFile("c:\\sss.exe",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0); if (createfile==INVALID_HANDLE_VALUE){ cout<<"Create File failed!"<<endl; goto next;} BOOL internetreadfile = 0; while(1){ internetreadfile=InternetReadFile(internetopenurl,buffer,sizeof(buffer),&byteread); if(byteread==0) break; hwrite=WriteFile(createfile,buffer,sizeof(buffer),&written,NULL); if (hwrite==0){ cout<<"Write to file failed!"<<endl; goto here;} } cout<<"Finished downloading!"<<endl; here: CloseHandle(createfile); next: InternetCloseHandle(internetopenurl); there: InternetCloseHandle(internetopen); }
之后研究研究断点传输
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。