cURL 挂在:"no chunk, no close, no size. Assume close to signal end"

cURL hangs at: "no chunk, no close, no size. Assume close to signal end"

当使用此命令将上传流式传输到 Apache/PHP 服务器时

curl -X POST \
-i --data-binary @customfile.app \
-H "Transfer-Encoding: chunked" \
-H "Content-Type: application/app" \
-H "X-CustomHeader1: customvalue1" \
-H "X-CustomHeader2: customvalue2" \
-H "X-CustomHeader3: customvalue3" \
-H "X-CustomHeader4: customvalue4" \
-H "X-CustomHeader5: customvalue5" \
-H "X-CustomHeader6: customvalue6" \
--ignore-content-length \
--progress-bar -vvv \
http://[DOMAIN]/upload.php

命令挂起如下:

* Hostname was NOT found in DNS cache
*   Trying [IP_ADDRESS]...
* Connected to [DOMAIN] ([IP_ADDRESS]) port 80 (#0)
> POST /upload.php HTTP/1.1
> User-Agent: curl/7.37.1
> Host: [DOMAIN]
> Accept: */*
> Transfer-Encoding: chunked
> Content-Type: application/app
> X-CustomHeader1: customvalue1
> X-CustomHeader2: customvalue2
> X-CustomHeader3: customvalue3
> X-CustomHeader4: customvalue4
> X-CustomHeader5: customvalue5
> X-CustomHeader6: customvalue6
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue

< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Date: Thu, 12 Feb 2015 11:10:17 GMT
Date: Thu, 12 Feb 2015 11:10:17 GMT
* Server Apache is not blacklisted
< Server: Apache
Server: Apache
< Vary: Content-Type
Vary: Content-Type
< Content-Length: 0
Content-Length: 0
< Connection: keep-alive
Connection: keep-alive
* no chunk, no close, no size. Assume close to signal end

<

现在,当 no chunk, no close, no size. Assume close to signal end 消息出现时,我对本地文件和服务器文件进行了校验和,以证明它们是相同的,确实如此。意思是文件上传成功,但是由于某种原因连接没有关闭。

为什么会这样,我该如何解决?我可以告诉 cURL 在整个文件上传后关闭连接吗?谢谢

你专门告诉curl忽略服务器设置的content-length。因此,响应的结束将被假定为连接关闭。但是服务器并没有关闭,因为它在等待更多的请求。

除此之外:我认为您不能将 "Transfer-Encoding: chunked" 添加为自定义 header。仅仅告诉服务器内容将以块的形式发送是不够的,但 curl 实际上必须使用它可能不会使用的块编码。

当 JSP 页面发生这种情况时,我有一个有趣的案例。

刷新换行有帮助:

<%
    out.println("");
    out.flush();
%>