英文:
Request param not picked when @ symbol present in path variable value
问题
以下是翻译好的部分:
我有一个如下所示的控制器:
@GetMapping(value = "/banking/accounts/customer/auth/{uniquePaymentId}")
public void clientAuth(@PathVariable("uniquePaymentId") @NotBlank(message = "uniquePaymentId should not be empty") final String uniquePaymentId,
@RequestParam(value = "consentId") final String consentId, final HttpServletResponse response) throws IOException {
String clientAuthUrl = openBankingService.getClientAuthUrl(uniquePaymentId, consentId);
response.sendRedirect(clientAuthUrl);
}
当我使用URL {{domain}}/v1/banking/accounts/customer/auth/test@test?consentId=value 调用API 时,
会得到以下错误:
{
"status": "INTERNAL_SERVER_ERROR",
"message": "Required String parameter 'consentId' is not present",
"errors": [
"Required String parameter 'consentId' is not present"
]
}
但是当我从URL (/auth/test@test?consentId=value) 中移除 @ 符号并调用时,一切正常。@ 符号是保留字符吗?
注意:我在使用 Postman 进行 API 调用。
英文:
I have a controller as following
@GetMapping(value = "/banking/accounts/customer/auth/{uniquePaymentId}")
public void clientAuth(@PathVariable("uniquePaymentId") @NotBlank(message = "uniquePaymentId should not be empty") final String uniquePaymentId,
@RequestParam(value = "consentId") final String consentId, final HttpServletResponse response) throws IOException {
String clientAuthUrl = openBankingService.getClientAuthUrl(uniquePaymentId, consentId);
response.sendRedirect(clientAuthUrl);
}
when I call the api with url {{domain}}/v1/banking/accounts/customer/auth/test@test?consentId=value
get following error
{
"status": "INTERNAL_SERVER_ERROR",
"message": "Required String parameter 'consentId' is not present",
"errors": [
"Required String parameter 'consentId' is not present"
]
}
but when I remove @ from url(/auth/test@test?consentId=value) and call everything works fine.
Is @ is reserved ?
Note: I'm using postman for the api call
答案1
得分: 2
@
在 URL 中使用时必须进行编码。URL 编码后的值为 %40
。
英文:
@
must be encoded when used in a URL. The URL-encoded value is %40
.
答案2
得分: -1
尝试使用以下内容来包含特殊字符:
@GetMapping(value = "/authenticate/google/{id:.+}", produces = MediaType.APPLICATION_JSON_VALUE)
{.+}
=> ".+" 允许在 Spring 控制器的路径变量中包含 "."。在您的情况下,请使用 "@" 替代 "." 并尝试。
英文:
Try using below to include special character
@GetMapping(value = "/authenticate/google/{id:.+}", produces = MediaType.APPLICATION_JSON_VALUE)
{.+}
=> ".+" allows "." to be included in path varialble in spring controller. Use "@" instead of "." in your case and try.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论