如何让Apache让我用Location标头定义“ 200 OK”响应的主体?

问题描述 投票:0回答:1

这是我在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 https://localhost/cgi-bin/test1
Hello world 1
cgi-bin> curl https://localhost/cgi-bin/test2
Hello world 1
cgi-bin> curl https://localhost/cgi-bin/test3
Hello world 3

注意/ cgi-bin / test2会忽略shell脚本打印的“ Hello world 2”正文,而是显示test1的输出。如何在不更改“状态”或“位置”标头的情况下使用“ Hello world 2”作为其响应?

apache http cgi httpd.conf
1个回答
0
投票

“位置响应标头表示将页面重定向到的URL。仅当与3xx(重定向)或201一起使用时才提供含义(已创建)状态响应。

在您的情况下,您向200发送的位置不符合要求。 Curl可能假设它是201,所以这里是应用的内容:

HTTP 201创建的成功状态响应代码表示请求成功,并导致了资源的创建。的有效地创建新资源,然后将该响应发送回去并且新资源将在邮件正文中返回location是请求的URL或请求的内容位置标题。

© www.soinside.com 2019 - 2024. All rights reserved.