通过http如何下载文件。

 1 None.gif void  OnDownload_thread( void   *  p)
 2 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 3 InBlock.gif    CClientDC dc( static_cast < CMainFrame *> (p));
 4 InBlock.gif    dc.TextOut( 50 100 " 正在下载最新版本迅雷,请等待dot.gif " );
 5 InBlock.gif
 6 InBlock.gif     char   * Url  =   " http://down.sandai.net:8080/Thunder5.1.5.189.exe " ;
 7 InBlock.gif    HINTERNET hSession  =  InternetOpen( " RookIE/1.0 " , INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL,  0 );
 8 InBlock.gif     if  (hSession  !=  NULL)
 9 ExpandedSubBlockStart.gifContractedSubBlock.gif     dot.gif {
10 InBlock.gif        HINTERNET handle2  =  InternetOpenUrl(hSession, Url, NULL,  0 , INTERNET_FLAG_DONT_CACHE,  0 );
11 InBlock.gif         if  (handle2  !=  NULL)
12 ExpandedSubBlockStart.gifContractedSubBlock.gif         dot.gif {
13 InBlock.gif            printf( " %s\n " ,Url);
14 InBlock.gif             byte  Temp[MAXBLOCKSIZE];
15 InBlock.gif            ULONG Number  =   1 ;
16 InBlock.gif            
17 InBlock.gif            FILE  * stream;
18 InBlock.gif             if ( (stream  =  fopen(  " d:\\Thunder5.1.5.189.exe " " wb "  ))  !=  NULL ) // 这里只是个测试,因此写了个死的文件路径
19 ExpandedSubBlockStart.gifContractedSubBlock.gif              dot.gif {
20 InBlock.gif                 while  (Number  >   0 )
21 ExpandedSubBlockStart.gifContractedSubBlock.gif                 dot.gif {
22 InBlock.gif                    InternetReadFile(handle2, Temp, MAXBLOCKSIZE  -   1 & Number);
23 InBlock.gif                     // fprintf(stream, (const char*)Temp);
24 InBlock.gif                     fwrite(Temp,  sizeof  ( char ), Number , stream);
25 ExpandedSubBlockEnd.gif                }

26 InBlock.gif                fclose( stream );
27 ExpandedSubBlockEnd.gif            }

28 InBlock.gif            
29 InBlock.gif            InternetCloseHandle(handle2);
30 InBlock.gif            handle2  =  NULL;
31 ExpandedSubBlockEnd.gif        }

32 InBlock.gif        InternetCloseHandle(hSession);
33 InBlock.gif        hSession  =  NULL;
34 ExpandedSubBlockEnd.gif    }

35 InBlock.gif
36 InBlock.gif
37 InBlock.gif     // CClientDC dc(this);
38 InBlock.gif     dc.TextOut( 80 100 " 下载完成。 " );
39 ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值