Delphi IdHttp组件+IdHttpServer组件实现文件下载服务

 http://blog.csdn.net/xxkku521/article/details/16864759

Delphi IdHttp组件+IdHttpServer组件实现文件下载服务

 分类:
 
[delphi] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  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 lazarus opengl 网页操作自动化, 图像分析破解,游戏开发
原文地址:https://www.cnblogs.com/delphi-xe5/p/5457075.html