【发布时间】:2021-05-14 00:54:28
【问题描述】:
我有一个 SpringBoot 应用程序。在控制器中使用此方法:
@GetMapping(value = "/")
public String home(Model model, HttpServletRequest request) {
System.out.println("home ->" + request.getRequestURI() + "<-");
}
但是当我从控制台执行时:
curl localhost:7080
curl localhost:7080/./
curl localhost:7080/../
curl localhost:7080/..
我总是得到相同的结果:home ->/<-
和浏览器的结果相同。我想为所有不是localhost:7080的映射返回404
我试过了:
MacBook-Pro-de-nunito:~ nunito$ curl --path--as-is localhost:7080/./
curl: option --path--as-is: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
curl --version
curl 7.64.1 (x86_64-apple-darwin20.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.41.0
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets
【问题讨论】:
-
好的。有问题吗?
-
有没有办法为所有与 / 不同的映射返回 404?
-
抱歉标志中的拼写错误,请使用
curl --path-as-is localhost:7080/./。我不小心在as之前添加了额外的-
标签: java spring spring-boot spring-mvc spring-security