http://blog.csdn.net/xxkku521/article/details/16864759Delphi idhttp Component +idhttpserver component for file download service2013-11-21 18:15 2624 People read comments (0) favorite reports Classification:DELPHI (Ten)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Delphi]View PlainCopy
- Uses idhttp,idhttpserver;
- Idhttp Component Submission Download request
- 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 ';//Request Address
- Try
- H. Get (Url,mystream); Submit Request except
- Application. Messagebox (' network error, please check network connection ',' Error box ', Mb_ok+mb_iconerror);
- MyStream. Free;
- H. Free;
- Exit
- end;
- MyStream. SaveToFile (Extractfilepath (Application. exename) +' system.ini ');
- MyStream. Free;
- H. Free;
- End
- Idhttpsever Component Response Request
- Procedure Tvodservice. Datamodulecreate (Sender:tobject); //Initialize Idhttpserver components
- 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 (' Load app settings error ' +e. Message);
- end;
- end;
- End
- Procedure Tvodservice. Vodhttpservercommandget (Athread:tidpeerthread;
- Arequestinfo:tidhttprequestinfo; Aresponseinfo:tidhttpresponseinfo); //Response Request
- Var
- bytesent:cardinal;
- Localdoc:string;
- Tempstr,ips:string;
- Len,sport:integer;
- Begin
- Tempstr:=arequestinfo. Document; //Get request string
- Ips:=tidiohandlersocket (Athread. Connection. Iohandler). Binding. PeerIP; //Get request address
- Sport:=tidiohandlersocket (Athread. Connection. Iohandler). Binding. Peerport; //Get request Port
- 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 (' no file found system.ini! ',' cue box ', mb_ok+mb_iconerror);
- end;
- End
Delphi Idhttp Component +idhttpserver component for file download service