Delphi IdHttp 구성 요소 + IdHttp Server 구성 요소 파일 다운로드 서비스

2043 단어 DELPHI
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;

좋은 웹페이지 즐겨찾기