当我在 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 库中是否有任何设置来禁用此行为?
最佳答案
Why is the REQUEST_URI being modified instead of passed thru untouched ?
事实并非如此。 URL 的更改由 cURL 在它到达服务器附近的任何地方之前进行。 ./
永远不会出现在发送到服务器的请求中。
./
表示“当前路径段”,因此它是多余的。客户端 (cURL) 在发出请求之前对其进行规范化。
您可以通过将对使用 curl
的请求的响应与手动构造 HTTP 请求时的响应进行比较来了解这一点。
手动构造请求
% 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
% curl http://localhost:7007/index.php/req.php/postcode/14482/city/./country/de/
Request:
/index.php/req.php/postcode/14482/city/country/de/
关于php - 为什么要修改 REQUEST_URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645538/