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

这是我在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标头。

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

  

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

在您的情况下,您向200发送了一个不符合要求的位置信息。 Curl可能假定它是201,因此适用以下方法:

  

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

由于您发送的标头有冲突,因此您无法要求Curl以有意义的方式进行处理。

出于好奇,您为什么还要这么做?资源应该是200、201或重定向,而不是两者的混合。如果您想将Location标头用于其他用途,则需要发送自定义标头,例如my-custom-location并对其进行相应处理。

,

按我的预期工作:

sap.m.input
本文链接:https://www.f2er.com/3069770.html

大家都在问