这是我在cgi-bin目录中的内容:
cgi-bin> cat test1
#!/bin/sh
echo "Status: 200 OK"
echo "Content-type: text/plain"
echo
echo "Hello world 1"
cgi-bin> cat test2
#!/bin/sh
echo "Status: 200 OK"
echo "Content-type: text/plain"
echo "Location: /cgi-bin/test1"
echo
echo "Hello world 2"
cgi-bin> cat test3
#!/bin/sh
echo "Status: 201 Created"
echo "Content-type: text/plain"
echo "Location: /cgi-bin/test1"
echo
echo "Hello world 3"
这是我对每个对象执行GET时得到的:
cgi-bin> curl -i https://localhost/cgi-bin/test1
HTTP/1.1 200 OK
Date: Wed,20 Nov 2019 15:56:43 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 1
cgi-bin> curl -i https://localhost/cgi-bin/test2
HTTP/1.1 200 OK
Date: Wed,20 Nov 2019 15:56:44 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 1
cgi-bin> curl -i https://localhost/cgi-bin/test3
HTTP/1.1 201 Created
Date: Wed,20 Nov 2019 15:56:45 GMT
Server: Apache
Location: /cgi-bin/test1
Transfer-Encoding: chunked
Content-Type: text/plain
Hello world 3
请注意,/ cgi-bin / test2会忽略外壳脚本打印的“ Hello world 2”正文,而是显示test1
的输出。如何在不更改“状态”或“位置”标头的情况下使用“ Hello world 2”作为响应?
编辑:更新了curl示例以包括HTTP标头。刚刚注意到/ cgi-bin / test2在响应中也不包含Location标头。