如何将服务器的HTTP响应设置为:
HTTP/1.1 206 Partial Content
在PHP中,我会写header('HTTP/1.1 206 Partial Content')
,但在Perl CGI中呢?
我正在使用此代码,但客户端报告HTTP 500错误
if ( defined $ENV{HTTP_RANGE} ) {
my $startrange = 500;
my $endrange = 900;
$length = $endrange-$startrange;
print qq{HTTP/1.1 206 Partial Content\n};
my $range = $startrange.'-'.$endrange.'/'.$filesize;
print qq{Content-Range: bytes $range\n};
}
print qq{Accept-Ranges: bytes\n};
print qq{Content-Disposition: attachment; filename="$filename"\n};
print qq{Content-length: $length\n\n};
我检查了错误日志,其中说明了这一点:
malformed header from script 'download.cgi': Bad header: HTTP/1.1 206 Partial Content
答案 0 :(得分:2)
您不应在CGI脚本中为HTTP status line发送Partial Content response。您的脚本应该发送正确的CGI response:
1 * header-field NL [response-body]
这应该有效:
Status: 206 Partial Content\n
Content-Range: bytes 500-900/12000\n
Content-Type: ?\n
您的脚本还必须发送Content-Type标头:
If an entity body is returned, the script MUST supply a Content-Type field in the response.