【问题标题】:Sending a cookie value with file download in perl在 perl 中通过文件下载发送 cookie 值
【发布时间】:2014-03-20 21:33:03
【问题描述】:

我在网页上有一个提交按钮,单击该按钮会执行文件下载。

我正在尝试禁用单击后提交(以防止在服务器端创建文件时重新提交),然后在下载文件时重新启用提交按钮。

简而言之,按照下面的教程,我几乎可以让它工作了:

  • 单击下载时,获取当前时间戳并将其存储在 隐藏字段
  • 将下载请求的时间戳发送到服务器
  • 服务器进行文件处理
  • 服务器使用客户端发送的时间戳值创建一个 cookie 在原始请求中
  • 服务器将 cookie 连同要下载的文件一起发送给客户端
  • 如果 cookie 值与隐藏字段时间戳匹配,则在客户端 提交已重新启用

Detecting file download in browser

问题是我似乎无法找到一种方法将 cookie 值与文件下载标头一起发送回客户端,如果我在标头中包含 set-cookie 它会破坏文件下载过程。

这是我当前的标题,它有效:

Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content

如果我这样做,它会中断:

Set-Cookie:$cookie; Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content

我正在使用来自客户端的时间戳值在服务器上创建一个 cookie:

$cookie = CGI::Cookie->new(-name=>'fileDownloadToken',-value=>"$token_value");

有谁知道我应该怎么做,用 Perl 编码?

【问题讨论】:

    标签: perl cookies http-headers submit download


    【解决方案1】:

    好的,我想我已经解决了。以防万一其他人对此提出异议,它似乎是标题的格式,而不是使用单个字符串:

    print qq(Content-disposition: attachment; filename=$file; Content-type: $type\n\n$content)
    

    我用过这个:

    print $page->header(
                -'cookie' => "$cookie",
                -'Content-disposition' => "attachment; filename=\"$file\"",
                -'Content-type' => $content
    );
    

    【讨论】:

      猜你喜欢
      • 2014-04-12
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 2012-04-17
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多