idhttpserver 下载文件
阅读原文时间:2023年07月11日阅读:1

procedure TForm30.IdHTTPServer1CommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
const
WEBROOT = 'C:\www';
const sb='C:\www\index.html';
var ss,s,s1,s3,s2:string; wenjian1,wenjian2,wenjian3:tstringlist; f1,f2,f3:string;
I: Integer;

var
RequestDocument:string;
begin
(* wenjian1:=tstringlist.Create;

if fileexists('c:\3fangan.txt') then
begin
wenjian1.LoadFromFile('c:\3fangan.txt');

wenjian1.Text:=trim(wenjian1.text);
end else
begin
{ s:=' '+' ' +'';
AResponseInfo.ContentText:=s;

exit; }
end;

//

memo1.Lines.Add(ARequestInfo.Document) ;
memo1.Lines.Add(arequestinfo.Params.Values['t1']) ;
memo1.Lines.Add(arequestinfo.Params.Values['t2']);

f1:='-1';f2:='-1';f3:='-1';

f1:=ARequestInfo.Document ;
f2:=arequestinfo.Params.Values['t1'] ;
f3:=arequestinfo.Params.Values['t2'];

if f2='-1' then begin // 默认访问
//-----------------------换行 变

ss:='';
for I := 0 to wenjian1.Count -1 do
begin
if length(trim(wenjian1.Strings[i]))<1 then continue;

ss:=ss+wenjian1.Strings[i]+'上面是第'+inttostr(i)+'个推送'+'
';
end;
ss:=copy(ss,1,length(ss)-5);
// wenjian1.Text:=ss;
//======================换行 变

wenjian1.Free;
end;

if f2='qing0' then //清除数据
begin
wenjian1.Clear;
wenjian1.SaveToFile('c:\3fangan.txt');
wenjian1.Free;
ss:='';
end;

if f2='1' then
begin
f3:=httpdecode(ARequestInfo.FormParams);// 这个是 post 的内容
// showmessage(f3);
wenjian1.Add(f3);
wenjian1.SaveToFile('c:\3fangan.txt');

//-----------------------换行 变

ss:='';
for I := 0 to wenjian1.Count -1 do
begin
if length(trim(wenjian1.Strings[i]))<1 then continue;

ss:=ss+wenjian1.Strings[i]+'上面是第'+inttostr(i)+'个推送'+'
';
end;
ss:=copy(ss,1,length(ss)-5);
// wenjian1.Text:=ss;
//======================换行 变

wenjian1.Free;
// showmessage(ss);
end;

AResponseInfo.ContentEncoding:='utf-8';
AResponseInfo.ContentType := 'text/html; charset=gb2312';

s:=' '+ss +'';
AResponseInfo.ContentText:=s; *)
//
{
AResponseInfo.ContentEncoding:='utf-8';
AResponseInfo.ContentType := 'text/html; charset=gb2312';
ss:=' ';
s:=' '+ss +'';
AResponseInfo.ContentText:=s;
// aresponseinfo.ServeFile(AContext,'c:\');

AResponseInfo.ContentText:='c:\abc.txt' ; }

{
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;
}

// AResponseInfo.ContentEncoding:='utf-8';
//AResponseInfo.ContentType := 'text/html; charset=gb2312';
//AResponseInfo.ContentDisposition:=Format('inline: filename="%s"',[ExtractFileName(s)]);

//AResponseInfo.CustomHeaders.Values['Content-Disposition'] :='attachment; filename="'+'192.168.0.101:12345/abc.txt'+'"';
//AResponseInfo.ServeFile(AContext,'192.168.0.101:12345/abc.txt');
//response
AResponseInfo.ContentType :='application/pdf';
//GetFileMIMEType
//AResponseInfo.ContentType := GetMIMEType(LocalDoc);
//application/x-rar-compressed
//aResponseInfo.ContentType := 'application/x-rar-compressed';

AResponseInfo.ServeFile(AContext,'c:\www\a.pdf');

end;

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章