#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); }
之后研究研究断点传输
用InternetOpen()的下载文件,布布扣,bubuko.com
原文地址:http://blog.csdn.net/heaven13483/article/details/38417957