Delphi IdHttp组件+IdHttpServer组件实现文件下载服务
2024-08-29 22:02:52
http://blog.csdn.net/xxkku521/article/details/16864759
Delphi IdHttp组件+IdHttpServer组件实现文件下载服务
分类:
DELPHI(10)
版权声明:本文为博主原创文章,未经博主允许不得转载。
- uses idhttp,IdHTTPServer;
- //idhttp组件提交下载请求
- procedure TVodService.Button3Click(Sender: TObject);
- var
- h:TIdhttp;
- MyStream:TMemoryStream;
- url:string;
- begin
- MyStream:=TMemoryStream.Create;
- h:=Tidhttp.Create(nil);
- url:='http://192.168.0.254:9003/GetIni';//请求地址
- try
- h.get(url,MyStream);//提交请求 except
- Application.Messagebox('网络出错,请检查网络连接','出错框',MB_OK+MB_ICONERROR) ;
- MyStream.Free;
- h.free;
- exit;
- end;
- MyStream.SaveToFile(extractfilepath(application.exename)+'System.ini');
- MyStream.Free;
- h.free;
- end;
- //IdHttpSever组件响应请求
- procedure TVodService.DataModuleCreate(Sender: TObject);//初始化IdHttpServer组件
- var
- hport:integer;
- Binding : TIdSocketHandle;
- begin
- try
- VodHttpServer.Bindings.Clear;
- Binding := VodHttpServer.Bindings.Add;
- Binding.Port:=9003;
- binding.IP:='192.168.0.254';
- VodHttpServer.Active:=true;
- except
- on e:Exception do
- begin
- FrmMain_VodSer.write_Logfile('加载APP设置error '+e.message);
- end;
- end;
- end;
- procedure TVodService.VodHttpServerCommandGet(AThread: TIdPeerThread;
- ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);//响应请求
- var
- ByteSent: Cardinal;
- LocalDoc:string;
- tempstr,ips:string;
- len,sport:integer;
- begin
- tempstr:=ARequestInfo.Document; //获取请求字符串
- ips:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerIP;//获取请求地址
- sport:=TIdIOHandlerSocket(AThread.Connection.IOHandler).Binding.PeerPort;//获取请求端口
- if fileexists(extractfilepath(application.exename)+'System.ini') then
- begin
- LocalDoc:=extractfilepath(application.exename)+'System.ini';
- ByteSent :=VodHttpServer.ServeFile(AThread, AResponseInfo, LocalDoc);
- end else
- begin
- Application.Messagebox('没有找到文件System.ini!','提示框',MB_OK+MB_ICONERROR) ;
- end;
- end;
最新文章
- navigationController 返回前N个视图
- Xcode7 使用NSURLSession发送HTTP请求的问题
- 【C#】线程之Parallel
- mysql数据库---同时插入两个表以上的数据
- Gson将参数放入实体类中进行包装之后再传递
- Linux Mysql 1130错误解决
- MyEclipse开发JAX-RS架构WebServices收发JSON数据格式
- Oracle ->;>; Oracle下生成序列的方法
- hdu 2818 Building Block(加权并查集)2009 Multi-University Training Contest 1
- swift基础--运算符
- Java之数组array和集合list、set、map
- java web 文件上传下载
- 小程序原理,生成SQL SERVER 2008 数据库所有表的结构文档
- 删除WIN7系统的共享文件
- Winform子窗体刷新父窗体
- javascript的this指向
- 关于基线baseline及与inline-block、vertical-aline等属性的关系(完善中.......)
- 关于js的页面高度和滚动条高度还有元素高度
- dbcontext实例创建问题
- 使用littleTools简化docker/kubectl的命令