gpt4 book ai didi

php - 使用 PHP 生成 HTTP 206 内容响应

转载 作者:搜寻专家 更新时间:2023-10-31 20:42:17 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 发送 HTTP 206 内容。但是不知何故,在收到 header 后,客户端报告关闭连接,即使我已经确认内容正在服务器上发送。

我认为它与 header 的设置或类似的东西有关。顶层代码是:

  $headers['content-length'] = $range['end']-$range['start']+1;

header('HTTP/1.1 206 Partial Content');
header("Pragma: {$headers['pragma']}");
header("Cache-Control: {$headers['cache-control']}");
header("Content-type: {$headers['content-type']}");
header("Content-Disposition: {$headers['content-disposition']}; filename=\"{$headers['filename']}\"");
header("Content-range: {$range['start']}-{$range['end']}/{$reqFile['size']}");
header("Content-length: {$headers['content-length']}");

outputFileRange($reqFile['handle'], $range['start'], $range['end']);

WGET 输出

当我尝试通过 wget 获取时:

$ wget -t 1 -d -SO /dev/null --header="X-Backend-Port: 80" --header="Range: bytes=50-" http://1.2.3.4/download/123.ogv

我得到以下信息:

Setting --server-response (serverresponse) to 1
Setting --output-document (outputdocument) to /dev/null
Setting --header (header) to X-Backend-Port: 80
Setting --header (header) to Range: bytes=50-
DEBUG output created by Wget 1.13.4 on linux-gnu.

URI encoding = `UTF-8'
--2013-10-18 11:05:36-- http://1.2.3.4/download/123.ogv
Connecting to 1.2.3.4:80... connected.
Created socket 4.
Releasing 0x0855da38 (new refcount 0).
Deleting unused 0x0855da38.

---request begin---
GET /download/123.ogv HTTP/1.1
User-Agent: Wget/1.13.4 (linux-gnu)
Accept: */*
Host: 1.2.3.4
Connection: Keep-Alive
X-Backend-Port: 80
Range: bytes=50-

---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 206 Partial Content
Server: nginx/0.7.67
Date: Fri, 18 Oct 2013 07:05:36 GMT
Content-Type: application/octet-stream
Connection: keep-alive
X-Powered-By: PHP/5.3.3-7+squeeze17
Pragma:
Cache-Control:
Content-Disposition: attachment; filename="123.ogv"
Content-range: 50-6642903/6642903
Content-length: 6642854

---response end---

HTTP/1.1 206 Partial Content
Server: nginx/0.7.67
Date: Fri, 18 Oct 2013 07:05:36 GMT
Content-Type: application/octet-stream
Connection: keep-alive
X-Powered-By: PHP/5.3.3-7+squeeze17
Pragma:
Cache-Control:
Content-Disposition: attachment; filename="123.ogv"
Content-range: 50-6642903/6642903
Content-length: 6642854
Registered socket 4 for persistent reuse.
Disabling further reuse of socket 4.
Closed fd 4


Giving up.

最佳答案

尝试设置内容范围:50-6642902/6642903根据 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

关于php - 使用 PHP 生成 HTTP 206 内容响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19443801/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com