【问题标题】:GET request with curl. No errors, but Content-Length equals 0使用 curl 获取请求。没有错误,但 Content-Length 等于 0
【发布时间】:2015-08-05 10:38:46
【问题描述】:

使用 curl 的简单 GET 请求返回空正文(内容长度:0):

curl -v https://www.flyorientthai.com/booking/en/index.php

另一方面,wget 可以很好地处理该网址:

wget https://www.flyorientthai.com/booking/en/index.php

卷曲有什么问题?

【问题讨论】:

  • 也许服务器需要某些 HTTP 标头,curl 通常不会发送但 wget 会发送
  • @MJafarMash 你是绝对正确的 :) curl 请求缺少“Connection: Keep-Alive”标头,结果证明它很关键。
  • 这是什么破服务器。 Keep-Alive 在 HTTP/1.1 中是隐含的,所以这个标头是多余的。但是是的,使用 curl -v -H "Connection: keep-alive" 会给出预期的响应,而没有标头则不会。

标签: linux ssl curl wget libcurl


【解决方案1】:

原来'Connection: Keep-Alive' 标头是必需的。它默认添加到使用 wget 请求而不是使用 curl。

【讨论】:

    【解决方案2】:

    对于在 Chrome 开发人员工具网络选项卡中使用“复制为 cURL”来生成 curl 命令的任何人 - 生成的 curl 命令中的一行是一个看起来像...的标题。

    -H 'If-None-Match: W/"18f6a6-6p8AL7X/p71IhN/WztZm60Aue4k"'
    

    如果没有任何更改,这会导致服务器返回空的 304 响应。把它抽出来。

    【讨论】:

      【解决方案3】:

      让我们试试“Content-Type: application/x-www-form-urlencodeds”

      【讨论】:

        猜你喜欢
        • 2023-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-13
        • 1970-01-01
        • 2020-03-01
        相关资源
        最近更新 更多