zoukankan      html  css  js  c++  java
  • indy idhttpserver有关下载的两个问题

    http://aawwmate.blog.163.com/blog/static/77528256201092733950315/

     

    indy idhttpserver有关下载的两个问题  

    2010-10-27 15:39:50|  分类: DELPHI|举报|字号 订阅

     
     

    1、IdHttpServer返回网页浏览器没直接显示,而是弹出下载对话框的解决方法

    最近用Indy10的TIdHttpServer写一个简单的http服务器,原来按网上一个indy9的方法返回服务器目录下的一个html文档,代码如下:

    procedure TForm3.IdHTTPServer1CommandGet(AContext: TIdContext;
    ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    const s='D:MyVclTestidCGIRunnerserverwebindex.html';
    begin
       //....
    AResponseInfo.ServeFile(AContext,s);

    //...
    end;

    结果在在游览器里打开时老出现下载对话框.试了好久,查看生成的http头如下:

    Connection: close
    Content-Disposition: attachment: filename="index.html";
    Content-Type: text/html
    Content-Length: 1265

    原来它把网页当附件传回来了,再跟Idhttpserver的代码,发现当AResponseInfo.ContentDisposition为空时它会自己加上attachment: filename="index.html";这个参数,经试验,当给AResponseInfo.ContentDisposition随便设一个值结果都是正常的.不过网上查看Content-Disposition的资料说正规的应该有个inline的参数......因此,改成下面就一切OK了:

    procedure TForm3.IdHTTPServer1CommandGet(AContext: TIdContext;
    ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
    const s='D:MyVclTestidCGIRunnerserverwebindex.html';
    begin
    AResponseInfo.ContentDisposition:=Format('inline: filename="%s"',[ExtractFileName(s)]);
    AResponseInfo.ServeFile(AContext,s);
    end;


    2、下载文件时,直接从网页打开而没有弹出保存对话框的问题解决

    AResponseInfo.CustomHeaders.Values['Content-Disposition'] :='attachment; filename="'+文件名+'"';

     
     
     
     
    阅读(1121)评论(0)
    delphi lazarus opengl 网页操作自动化, 图像分析破解,游戏开发
  • 相关阅读:
    DataFrame遍历所有元素
    linux 安装redis 和系统学习redis
    接口
    安装idea教程
    Hello World!
    通过特征交互检测生成文本分类的层次解释《Generating Hierarchical Explanations on Text Classification via Feature Interaction Detection》(LIME算法、神经网络预测的分层解释CD和ACD、Shapley Value夏普利值、Leave-One-Out留一法、HEDGE)
    数字图像处理 乱记
    高傲的审稿人
    两项技能
    人其实会变的
  • 原文地址:https://www.cnblogs.com/delphi-xe5/p/5457069.html
Copyright © 2011-2022 走看看