当我在req.php中运行以下代码时:
<?php
echo("Request:\n");
print_r($_SERVER['REQUEST_URI']);
?>
请求:
curl "http://localhost/req.php/postcode/14482/city/./country/de/"
我收到了这个回复:
Request:
/req.php/postcode/14482/city/country/de/
当我在/ city之后使用两个点时:
Request:
/req.php/postcode/14482/country/de/
在/ city之后有三个点:
Request:
/req.php/postcode/14482/city/.../country/de/
为什么要修改REQUEST_URI而不是通过未经修改的传递?
编辑:看来cURL正在编辑REQUEST_URI - cURL php库中是否有任何设置可以禁用此行为?
答案 0 :(得分:3)
为什么要修改REQUEST_URI而不是通过未经修改的传递?
不是。对URL的更改是在cURL到达服务器附近之前进行的。 ./
永远不会发送到服务器的请求中。
./
表示&#34;当前路径段&#34;所以这是多余的。客户端(cURL)在发出请求之前对其进行规范化。
您可以通过手动构建HTTP请求时将对curl
请求的响应与响应进行比较来看到这一点。
% telnet localhost 7007
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET /index.php/req.php/postcode/14482/city/./country/de/
HTTP/0.9 200 OK
Date: Wed, 04 Apr 2018 07:53:23 +0000
Connection: close
X-Powered-By: PHP/7.1.7
Content-type: text/html; charset=UTF-8
Request:
/index.php/req.php/postcode/14482/city/./country/de/
Connection closed by foreign host.
% curl http://localhost:7007/index.php/req.php/postcode/14482/city/./country/de/
Request:
/index.php/req.php/postcode/14482/city/country/de/