使用此命令将上传流式传输到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在整个文件上传后关闭连接吗?感谢
答案 0 :(得分:2)
您明确告诉curl忽略服务器设置的内容长度。因此,响应的结束将被假定为连接关闭。但服务器没有关闭,因为它等待更多请求。
除此之外:我认为你不能只将“Transfer-Encoding:chunked”添加为自定义标题。仅告诉服务器内容将以块的形式发送是不够的,但curl实际上必须使用可能不会使用的分块编码。
答案 1 :(得分:0)
当JSP页面发生这种情况时,我有一个有趣的例子。
刷新换行符有帮助:
<%
out.println("");
out.flush();
%>