http - 要求 CURL 在收到 header 后立即断开连接

标签 http curl

我正在从服务器提取数据,但在提取数据之前需要知道数据的类型。我知道我可以查看响应 header 中的内容类型,并且我已经研究过使用

curl --head http://x.com/y/z

但是有些服务器不支持“HEAD”命令(我收到 501 未实现响应)。

是否有可能以某种方式使用curl执行GET,并在收到所有 header 后立即断开连接?

最佳答案

查看以下答案:

https://stackoverflow.com/a/5787827

Streaming. UNIX philosphy and pipes: they are data streams. Since curl and GET are unix filters, ending the receiving pipe (dd) will terminate curl or GET early (SIGPIPE). There is no telling whether the server will be smart enough to stop transmission. However on a TCP level I suppose it would stop retrying packets once there is no more response. @sehe

使用此方法,您应该能够下载所需数量的字节,然后取消请求。您还可以使用一些魔法在收到空行后终止,这意味着 header 的结束。

关于http - 要求 CURL 在收到 header 后立即断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11655170/

相关文章:

node.js - 检测 S3 对象的内容类型/MIME 类型

ios - Swift 将 cURL -user key 转换为 AFNetworking 的 json

CURL命令行工具-从FTP服务器删除文件

http - 我想检查某个端口是否打开(Haskell)?

rest - 来自 curl 的跨源调用在不需要 header 的情况下工作

c++ - 我需要做什么才能使 Boost.Beast HTTP 解析器找到正文的结尾?

在 bash 脚本中使用 cURL 的 Javascript 登录

php - cURL 需要 CURLOPT_SSL_VERIFYPEER=FALSE

python - libcurl ubuntu python 中不支持或禁用协议(protocol) "https"

internet-explorer - FF 和 IE 之间重新加载行为的差异