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

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

2013-11-21 18:15 2624人阅读 评论(0) 收藏 举报
 分类:
DELPHI(10) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

  1. uses idhttp,IdHTTPServer;
  2. //idhttp组件提交下载请求
  3. procedure TVodService.Button3Click(Sender: TObject);
  4. var
  5. h:TIdhttp;
  6. MyStream:TMemoryStream;
  7. url:string;
  8. begin
  9. MyStream:=TMemoryStream.Create;
  10. h:=Tidhttp.Create(nil);
  11. url:='http://192.168.0.254:9003/GetIni';//请求地址
  12. try
  13. h.get(url,MyStream);//提交请求     except
  14. Application.Messagebox('网络出错,请检查网络连接','出错框',MB_OK+MB_ICONERROR) ;
  15. MyStream.Free;
  16. h.free;
  17. exit;
  18. end;
  19. MyStream.SaveToFile(extractfilepath(application.exename)+'System.ini');
  20. MyStream.Free;
  21. h.free;
  22. end;
  23. //IdHttpSever组件响应请求
  24. procedure TVodService.DataModuleCreate(Sender: TObject);//初始化IdHttpServer组件
  25. var
  26. hport:integer;
  27. Binding : TIdSocketHandle;
  28. begin
  29. try
  30. VodHttpServer.Bindings.Clear;
  31. Binding := VodHttpServer.Bindings.Add;
  32. Binding.Port:=9003;
  33. binding.IP:='192.168.0.254';
  34. VodHttpServer.Active:=true;
  35. except
  36. on e:Exception do
  37. begin
  38. FrmMain_VodSer.write_Logfile('加载APP设置error '+e.message);
  39. end;
  40. end;
  41. end;
  42. procedure TVodService.VodHttpServerCommandGet(AThread: TIdPeerThread;
  43. ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);//响应请求
  44. var
  45. ByteSent: Cardinal;
  46. LocalDoc:string;
  47. tempstr,ips:string;
  48. len,sport:integer;
  49. begin
  50. tempstr:=ARequestInfo.Document; //获取请求字符串
  51. ips:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerIP;//获取请求地址
  52. sport:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerPort;//获取请求端口
  53. if fileexists(extractfilepath(application.exename)+'System.ini') then
  54. begin
  55. LocalDoc:=extractfilepath(application.exename)+'System.ini';
  56. ByteSent :=VodHttpServer.ServeFile(AThread, AResponseInfo, LocalDoc);
  57. end else
  58. begin
  59. Application.Messagebox('没有找到文件System.ini!','提示框',MB_OK+MB_ICONERROR) ;
  60. end;
  61. end;

最新文章

  1. navigationController 返回前N个视图
  2. Xcode7 使用NSURLSession发送HTTP请求的问题
  3. 【C#】线程之Parallel
  4. mysql数据库---同时插入两个表以上的数据
  5. Gson将参数放入实体类中进行包装之后再传递
  6. Linux Mysql 1130错误解决
  7. MyEclipse开发JAX-RS架构WebServices收发JSON数据格式
  8. Oracle ->> Oracle下生成序列的方法
  9. hdu 2818 Building Block(加权并查集)2009 Multi-University Training Contest 1
  10. swift基础--运算符
  11. Java之数组array和集合list、set、map
  12. java web 文件上传下载
  13. 小程序原理,生成SQL SERVER 2008 数据库所有表的结构文档
  14. 删除WIN7系统的共享文件
  15. Winform子窗体刷新父窗体
  16. javascript的this指向
  17. 关于基线baseline及与inline-block、vertical-aline等属性的关系(完善中.......)
  18. 关于js的页面高度和滚动条高度还有元素高度
  19. dbcontext实例创建问题
  20. 使用littleTools简化docker/kubectl的命令

热门文章

  1. 自动生成脚本头部格式并调用VIM工具
  2. 在虚拟机Linux中安装VMTools遇到的问题-小结
  3. poj 1269 Intersecting Lines(直线相交)
  4. wireshare文件格式
  5. fastjson合并json数组中相同的某个元素
  6. phpStorm 配置PHP_CodeSniffer自动检查代码
  7. springboot 集成rabbitMQ
  8. pandas学习(一)
  9. 利用xcode Build生成模拟器运行包
  10. 对Promise的研究4