首页 > 代码库 > 用InternetOpen()的下载文件
用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); }
之后研究研究断点传输
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。