有没有办法强制 HTTP 服务器通过 libcurl 向我发送特定的 header?
Is there a way to force HTTP server to send me a specific header via libcurl?
具体来说Content-Length
。当我向我的本地服务器发送 HEAD 请求时,我并不总是收到请求文件的大小。
例如,当它是 159 字节时 index.php:
HTTP/1.1 200 OK
Date: Wed, 31 Aug 2016 11:34:16 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.20
X-Powered-By: PHP/5.6.20
Content-Type: text/html; charset=UTF-8
还有 40 MB 左右的随机 .pdf 文件:
HTTP/1.1 200 OK
Date: Wed, 31 Aug 2016 11:34:23 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.20
Last-Modified: Thu, 25 Aug 2016 11:19:59 GMT
ETag: "2807fb2-53ae39413d130"
Accept-Ranges: bytes
Content-Length: 41975730
Content-Type: application/pdf
能不能强制?
不,你不能。尺码要么有货,要么没有。
特别是php脚本,内容是动态生成的,事先不知道大小。
本质上,HEAD
与 GET
的作用相同,但省略了负载。
具体来说Content-Length
。当我向我的本地服务器发送 HEAD 请求时,我并不总是收到请求文件的大小。
例如,当它是 159 字节时 index.php:
HTTP/1.1 200 OK
Date: Wed, 31 Aug 2016 11:34:16 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.20
X-Powered-By: PHP/5.6.20
Content-Type: text/html; charset=UTF-8
还有 40 MB 左右的随机 .pdf 文件:
HTTP/1.1 200 OK
Date: Wed, 31 Aug 2016 11:34:23 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.20
Last-Modified: Thu, 25 Aug 2016 11:19:59 GMT
ETag: "2807fb2-53ae39413d130"
Accept-Ranges: bytes
Content-Length: 41975730
Content-Type: application/pdf
能不能强制?
不,你不能。尺码要么有货,要么没有。
特别是php脚本,内容是动态生成的,事先不知道大小。
本质上,HEAD
与 GET
的作用相同,但省略了负载。