Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi indy将文件发送到客户端并运行_Delphi_Server_Indy - Fatal编程技术网

Delphi indy将文件发送到客户端并运行

Delphi indy将文件发送到客户端并运行,delphi,server,indy,Delphi,Server,Indy,我正在制作一个小型服务器类型的应用程序 在web浏览器中,我希望用户输入服务器地址和登录名,然后我的服务器必须返回服务器上存在的文件的路径。该文件必须在用户的本地计算机上运行(这些是小的Excel文件,因此可能工作得很快) 有可能吗?我必须先下载文件,然后运行它吗 该文件应在登录后自动运行,因此我的服务器必须将该文件发送到客户端计算机并在客户端计算机上运行 你能给我举个小例子吗 另外,我使用Indy组件,但如果有人有更好的想法,我愿意接受建议。您所要求的在HTTP技术上是可行的,因为对任何HTT

我正在制作一个小型服务器类型的应用程序

在web浏览器中,我希望用户输入服务器地址和登录名,然后我的服务器必须返回服务器上存在的文件的路径。该文件必须在用户的本地计算机上运行(这些是小的Excel文件,因此可能工作得很快)

有可能吗?我必须先下载文件,然后运行它吗

该文件应在登录后自动运行,因此我的服务器必须将该文件发送到客户端计算机并在客户端计算机上运行

你能给我举个小例子吗


另外,我使用Indy组件,但如果有人有更好的想法,我愿意接受建议。

您所要求的在HTTP技术上是可行的,因为对任何HTTP请求的响应都可能是实际的Excel文件。例如:

使用HTTP身份验证:

procedure TMyForm.IdHTTPServer1CommandGet(AContext:TIdContext;ARequestInfo:TIdHTTPRequestInfo;AResponseInfo:TIdHTTPResponseInfo);
开始
如果ARequestInfo.Document='/myfile.xlsx',则
开始
如果不存在ARequestInfo.auth,则
开始
AResponseInfo.AuthRealm:=“myserver”;
出口
结束;
如果未对用户进行身份验证(ARequestInfo.AuthUsername、ARequestInfo.AuthPassword),则
开始
AResponseInfo.ResponseNo:=403;
出口
结束;
案例ARequestInfo.CommandType of
hcGET:
开始
AResponseInfo.SmartServeFile(AContext,ARequestInfo,'\myfile.xlsx');
结束;
hcHEAD:
开始
AresOnSeInfo.ContentType:=IdHTTPServer1.MIMETable.GetFileMiMetType('myfile.xlsx');
AResponseInfo.ContentLength:=FileSizeByName('\myfile.xlsx');
AresOnSeInfo.ContentDisposition:='附件;filename=“myfile.xlsx”;
结束;
其他的
AResponseInfo.ResponseNo:=405;
结束;
结束其他
开始
AResponseInfo.ResponseNo:=404;
结束;
结束;
使用HTML Web表单身份验证:

index.html


登录
用户名:
密码:
procedure TMyForm.IdHTTPServer1CommandGet(AContext:TIdContext;ARequestInfo:TIdHTTPRequestInfo;AResponseInfo:TIdHTTPResponseInfo);
开始
如果ARequestInfo.Document='/'那么
开始
案例ARequestInfo.CommandType of
hcGET,hcHEAD:
开始
AResponseInfo.ContentType:=“文本/html”;
如果ARequestInfo.CommandType=hcGET,则
AresOnSeInfo.ContentStream:=TIdReadFileExclusiveStream.Create('\index.html'))
其他的
AResponseInfo.ContentLength:=FileSizeByName('\index.html');
结束;
其他的
AResponseInfo.ResponseNo:=405;
结束;
结束
否则,如果ARequestInfo.Document='/login',则
开始
如果是RequestInfo.CommandType hcPOST,则
开始
AResponseInfo.ResponseNo:=405;
出口
结束;
如果未对用户进行身份验证(ARequestInfo.Params.Values['user'],ARequestInfo.Params.Values['pswd']),则
开始
AResponseInfo.ResponseNo:=403;
出口
结束;
AResponseInfo.ServeFile(AContext,“\myfile.xlsx”);
结束其他
开始
AResponseInfo.ResponseNo:=404;
结束;
结束;
或者:

//确保设置TIdHTTPServer.SessionState=True。。。
过程TMyForm.IdHTTPServer1CommandGet(AContext:TIdContext;ARequestInfo:TIdHTTPRequestInfo;AResponseInfo:TIdHTTPResponseInfo);
开始
如果ARequestInfo.Document='/'那么
开始
案例ARequestInfo.CommandType of
hcGET,hcHEAD:
开始
AResponseInfo.ContentType:=“文本/html”;
如果ARequestInfo.CommandType=hcGET,则
AresOnSeInfo.ContentStream:=TIdReadFileExclusiveStream.Create('\index.html'))
其他的
AResponseInfo.ContentLength:=FileSizeByName('\index.html');
结束;
其他的
AResponseInfo.ResponseNo:=405;
结束;
结束
否则,如果ARequestInfo.Document='/login',则
开始
如果是RequestInfo.CommandType hcPOST,则
开始
AResponseInfo.ResponseNo:=405;
出口
结束;
如果ARequestInfo.Session=nil,则
开始
IdHTTPServer1.CreateSession(AContext、AresOnSeInfo、ARequestInfo);
结束;
如果未对用户进行身份验证(ARequestInfo.Params.Values['user'],ARequestInfo.Params.Values['pswd']),则
开始
AResponseInfo.Session.Content.Values['AuthOK']:=“否”;
AResponseInfo.ResponseNo:=403;
出口
结束;
AResponseInfo.Session.Content.Values['AuthOK']:='yes';
//重定向('/myfile.xlsx');
AResponseInfo.ResponseNo:=303;
AResponseInfo.Location:='/myfile.xlsx';
结束
否则,如果ARequestInfo.Document='/myfile.xlsx',则
开始
如果存在ARequestInfo.auth,则
开始
如果ARequestInfo.Session=nil,则
开始
IdHTTPServer1.CreateSession(AContext、AresOnSeInfo、ARequestInfo);
结束;
ARequestInfo.Session.Content.Values['AuthOK']:=iif(UserIsAuthenticated(ARequestInfo.AuthUsername,ARequestInfo.AuthPassword),'yes','no');
结束;
如果(ARequestInfo.Session=nil)或(ARequestInfo.Session.Content.IndexOf('AuthOK')=-1),则
开始
//AResponseInfo.Redirect('/');
AResponseInfo.ResponseNo:=303;
AResponseInfo.Location:='/';
出口
结束;
如果ARequestInfo.Session.Content.Values['AuthOK']“yes”,则
开始
AResponseInfo.ResponseNo:=403;
出口
结束;
案例ARequestInfo.CommandType of
hcGET:
开始
AResponseInfo.SmartServeFile(AContext,ARequestInfo,'\myfile.xlsx');
结束;
hcHEAD:
开始
AresOnSeInfo.ContentType:=IdHTTPServer1.MIMETable.GetFileMiMetType('myfile.xlsx');
AResponseInfo.ContentLength:=FileSizeByName('\myfile.xlsx');
AresOnSeInfo.ContentDisposition:='附件;filename=“myfile.xlsx”;
结束;
其他的
AResponseInfo.ResponseNo:=405;
结束;
结束其他
开始
AResponseInfo.ResponseNo:=404;
结束;
结束;
但是,无论哪种方式,用户的web浏览器都必须配置为