问题描述
首先使用get
方法请求apache的一个CGI,返回预期结果,然后换成post
方法,结果返回如下错误:
curl: (18) transfer closed with outstanding read data remaining
错误的大致意思是:需要读取的数据还没有完成,但是传输数据的连接被关闭了。通过man curl也可以查到返回码18的错误描述,Partial file. Only a part of the file was transferred.
服务端CGI的代码很简单,只是构造了一个应答:
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo $REQUEST_METHOD >> /tmp/somelog.gerry
# ok, we've sent the header, now send some content
echo "{\"ret\":0,\"msg\":\"ok\"}"
- 客户端使用
get
方法调用(可以正常返回):
$curl -v "http://10.137.142.144/cgi-bin/test.sh?a=b&c=d"
* About to connect() to 10.137.142.144 port 80 (#0)
* Trying 10.137.142.144... connected
* Connected to 10.137.142.144 (10.137.142.144) port 80 (#0)
> GET /cgi-bin/test.sh?a=b&c=d HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2
> Host: 10.137.142.144
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 08 Apr 2016 05:49:48 GMT
< Server: Apache/2.4.2 (Unix)
< Transfer-Encoding: chunked
< Content-Type: text/html
<
{
"ret":0,"msg":"ok"}
* Connection #0 to host 10.137.142.144 left intact
* Closing connection #0
- 客户端使用
post
方法调用(出现curl: (18)错误):
$curl -v -d"a=b&c=d" http://10.137.142.144/cgi-bin/test.sh
* About to connect() to 10.137.142.144 port 80 (#0)
* Trying 10.137.142.144... connected
* Connected to 10.137.142.144 (10.137.142.144) port 80 (#0)
> POST /cgi-bin/test.sh HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.