怎样用idhttpserver代替IIS让用户浏览html或下载文件

解决方案 »

  1.   


    procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    const
      WEBROOT = 'C:/www';
    var
      RequestDocument:string;
    begin
      RequestDocument:=LowerCase(ARequestInfo.Document);  if RequestDocument='/' then
        RequestDocument:='/index.html';  if FileExists(WEBROOT+RequestDocument) then
        begin
          AResponseInfo.ContentStream:=TFileStream.Create(WEBROOT+RequestDocument, fmOpenRead + fmShareDenyWrite);
        end
      else 
        begin
          AResponseInfo.ResponseNo := 404;
        end;  AResponseInfo.Server:='IIS/6.0';
      AResponseInfo.CacheControl:='no-cache';
      AResponseInfo.Pragma:='no-cache';
      AResponseInfo.Date:=Now;
      

  2.   


    procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread;
      ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    const
      WEBROOT = 'C:/www';
    var
      RequestDocument:string;
    begin
      RequestDocument:=LowerCase(ARequestInfo.Document);  if RequestDocument='/' then
        RequestDocument:='/index.html';  if FileExists(WEBROOT+RequestDocument) then
        begin
          AResponseInfo.ContentStream:=TFileStream.Create(WEBROOT+RequestDocument, fmOpenRead + fmShareDenyWrite);
        end
      else 
        begin
          AResponseInfo.ResponseNo := 404;
        end;  AResponseInfo.Server:='IIS/6.0';
      AResponseInfo.CacheControl:='no-cache';
      AResponseInfo.Pragma:='no-cache';
      AResponseInfo.Date:=Now;end;
    这段代码的话,应付一般的html网站应该足够了...