请求参数未被提取,当路径变量值中存在 “@” 符号时。

huangapple go评论136阅读模式
英文:

Request param not picked when @ symbol present in path variable value

问题

以下是翻译好的部分:

我有一个如下所示的控制器:

  1. @GetMapping(value = "/banking/accounts/customer/auth/{uniquePaymentId}")
  2. public void clientAuth(@PathVariable("uniquePaymentId") @NotBlank(message = "uniquePaymentId should not be empty") final String uniquePaymentId,
  3. @RequestParam(value = "consentId") final String consentId, final HttpServletResponse response) throws IOException {
  4. String clientAuthUrl = openBankingService.getClientAuthUrl(uniquePaymentId, consentId);
  5. response.sendRedirect(clientAuthUrl);
  6. }

当我使用URL {{domain}}/v1/banking/accounts/customer/auth/test@test?consentId=value 调用API 时,

会得到以下错误:

  1. {
  2. "status": "INTERNAL_SERVER_ERROR",
  3. "message": "Required String parameter 'consentId' is not present",
  4. "errors": [
  5. "Required String parameter 'consentId' is not present"
  6. ]
  7. }

但是当我从URL (/auth/test@test?consentId=value) 中移除 @ 符号并调用时,一切正常。@ 符号是保留字符吗?

注意:我在使用 Postman 进行 API 调用。

英文:

I have a controller as following

  1. @GetMapping(value = "/banking/accounts/customer/auth/{uniquePaymentId}")
  2. public void clientAuth(@PathVariable("uniquePaymentId") @NotBlank(message = "uniquePaymentId should not be empty") final String uniquePaymentId,
  3. @RequestParam(value = "consentId") final String consentId, final HttpServletResponse response) throws IOException {
  4. String clientAuthUrl = openBankingService.getClientAuthUrl(uniquePaymentId, consentId);
  5. response.sendRedirect(clientAuthUrl);
  6. }

when I call the api with url {{domain}}/v1/banking/accounts/customer/auth/test@test?consentId=value

get following error

  1. {
  2. "status": "INTERNAL_SERVER_ERROR",
  3. "message": "Required String parameter 'consentId' is not present",
  4. "errors": [
  5. "Required String parameter 'consentId' is not present"
  6. ]
  7. }

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

尝试使用以下内容来包含特殊字符:

  1. @GetMapping(value = "/authenticate/google/{id:.+}", produces = MediaType.APPLICATION_JSON_VALUE)

{.+} => ".+" 允许在 Spring 控制器的路径变量中包含 "."。在您的情况下,请使用 "@" 替代 "." 并尝试。

英文:

Try using below to include special character

  1. @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.

huangapple
  • 本文由 发表于 2020年9月25日 14:33:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/64059013.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定