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 网页操作自动化, 图像分析破解,游戏开发
  • 相关阅读:
    Idea中提交SVN或git时,忽略某些文件不提交
    SVN(subversion )服务端和客户端的下载安装使用
    layui官方文档
    使用IntelliJ IDEA配置Tomcat
    IntelliJ IDEA 配置JDK
    设置 IntelliJ IDEA 主题
    mybatis+mysql批量插入和批量更新
    session.资料
    MyEclipse2014.Maven自动更新
    Office.资料
  • 原文地址:https://www.cnblogs.com/delphi-xe5/p/5457069.html
Copyright © 2011-2022 走看看