首页 > Web开发 > 详细

用InternetOpen()的下载文件

时间:2014-08-07 15:52:10      阅读:262      评论:0      收藏:0      [点我收藏+]
#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

用InternetOpen()的下载文件

原文:http://blog.csdn.net/heaven13483/article/details/38417957

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!