Http

使用 cURL 向 IP 發送 Web 請求時如何指定 GET 路徑?

  • March 18, 2022

使用以下命令的輸出,

% curl -v stackoverflow.com/questions       
* About to connect() to stackoverflow.com port 80 (#0)
*   Trying 198.252.206.16...
* Connected to stackoverflow.com (198.252.206.16) port 80 (#0)
> GET /questions HTTP/1.1
> User-Agent: curl/7.29.0
> Host: stackoverflow.com
> Accept: */*

我可以curl -X GET -H "User-Agent: curl/7.29.0" -H "Host: stackoverflow.com" -H "Accept: */*" 198.252.206.16複製請求,但如何GET /questions在命令中指定?

stackoverflow.com/questions

= 獲取/問題

stackoverflow.com/87whjjgaas.asd

= 獲取 /87whjjgaas.asd

23.123.123.123/questions

= 獲取/問題

為了

curl -X GET -H“使用者代理:curl/7.29.0”-H“主機:stackoverflow.com”-H“接受:/ ”198.252.206.16

答案是

curl -X GET -H“使用者代理:curl/7.29.0”-H“主機:stackoverflow.com”-H“接受:/ ”198.252.206.16/questions

:)

我需要查看伺服器在某些“錯誤”路徑下的行為。要阻止 curl 規範化路徑,可以--path-as-is選擇。

curl --path-as-is http://www.example.com/_cdn_assets_/./../font-awesome/4.3.0/css/font-awesome.css

引用自:https://serverfault.com/questions/536854