gpt4 book ai didi

java - 如何处理包含正斜杠的请求?

转载 作者:行者123 更新时间:2023-12-02 02:49:53 24 4
gpt4 key购买 nike

我的 URL 请求是 http://localhost:8080/login/verify/212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=

我需要获取以下部分:**212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=**

以下代码不起作用:

@RequestMapping(value = "/login/verify/{request:.+}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public ResponseEntity verifyLogin(@PathVariable(value = "request") String request)
throws InvalidSignatureException
{
}

错误:HTTP 状态 404。

Spring 无法处理此请求。

最佳答案

要将 uri 与斜杠匹配,请使用双 *

@RequestMapping(value = "/login/verify/**",

然后,在正文中获取值时,您将使用

String str = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)

示例代码:

@RequestMapping(value = "/login/verify/**", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) 
public ResponseEntity verifyLogin(HttpServletRequest httpServletRequest) throws InvalidSignatureException {
String str = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)
}

关于java - 如何处理包含正斜杠的请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44015637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com