Delphi IdHttp組件+IdHttpServer組件實現檔案下載服務

來源:互聯網
上載者:User

標籤:

 http://blog.csdn.net/xxkku521/article/details/16864759Delphi IdHttp組件+IdHttpServer組件實現檔案下載服務2013-11-21 18:15 2624人閱讀 評論(0) 收藏 舉報 分類: DELPHI(10) 

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

[delphi] view plain copy  
  1. uses idhttp,IdHTTPServer;  
  2.   
  3. //idhttp組件提交下載請求  
  4. procedure TVodService.Button3Click(Sender: TObject);   
  5. var   
  6.     h:TIdhttp;   
  7.     MyStream:TMemoryStream;   
  8.     url:string;  
  9. begin   
  10.     MyStream:=TMemoryStream.Create;   
  11.     h:=Tidhttp.Create(nil);   
  12.     url:=‘http://192.168.0.254:9003/GetIni‘;//請求地址         
  13.     try   
  14.         h.get(url,MyStream);//提交請求     except     
  15.         Application.Messagebox(‘網路出錯,請檢查網路連接‘,‘出錯框‘,MB_OK+MB_ICONERROR) ;  
  16.         MyStream.Free;  
  17.         h.free;   
  18.         exit;   
  19.     end;   
  20.     MyStream.SaveToFile(extractfilepath(application.exename)+‘System.ini‘);   
  21.     MyStream.Free;   
  22.     h.free;  
  23. end;  
  24.   
  25. //IdHttpSever組件響應請求  
  26. procedure TVodService.DataModuleCreate(Sender: TObject);//初始化IdHttpServer組件  
  27. var  
  28.     hport:integer;  
  29.     Binding : TIdSocketHandle;  
  30. begin  
  31.     try  
  32.         VodHttpServer.Bindings.Clear;  
  33.         Binding := VodHttpServer.Bindings.Add;  
  34.         Binding.Port:=9003;  
  35.         binding.IP:=‘192.168.0.254‘;  
  36.         VodHttpServer.Active:=true;  
  37.     except  
  38.         on e:Exception do  
  39.             begin  
  40.                  FrmMain_VodSer.write_Logfile(‘載入APP設定error ‘+e.message);  
  41.             end;  
  42.     end;  
  43. end;   
  44.   
  45.   
  46. procedure TVodService.VodHttpServerCommandGet(AThread: TIdPeerThread;  
  47.   ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);//響應請求  
  48. var  
  49.     ByteSent: Cardinal;  
  50.     LocalDoc:string;  
  51.     tempstr,ips:string;  
  52.     len,sport:integer;  
  53. begin  
  54.     tempstr:=ARequestInfo.Document; //擷取請求字串  
  55.     ips:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerIP;//擷取請求地址  
  56.     sport:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerPort;//擷取請求連接埠  
  57.     if fileexists(extractfilepath(application.exename)+‘System.ini‘) then  
  58.     begin  
  59.         LocalDoc:=extractfilepath(application.exename)+‘System.ini‘;  
  60.         ByteSent :=VodHttpServer.ServeFile(AThread, AResponseInfo, LocalDoc);  
  61.     end else  
  62.     begin  
  63.         Application.Messagebox(‘沒有找到檔案System.ini!‘,‘提示框‘,MB_OK+MB_ICONERROR) ;  
  64.     end;  
  65. end;  

Delphi IdHttp組件+IdHttpServer組件實現檔案下載服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.