当使用这样的请求处理程序调用 GEThttp://localhost:8080/things/ZhaD2lk27XQPRJtwrABltd+UTWXcbnY%2FTrpxGP7VDVo=
我的 Spring Boot 应用程序 RestController 时:
@RequestMapping("/things/{thingId}")
public ResponseEntity<Thing> getThing(
@PathVariable String thingId) {
System.out.println("thingId=" + thingId);
...
导致打印以下内容,ZhaD2lk27XQPRJtwrABltd UTWXcbnY/TrpxGP7VDVo=
而不是我所期望的ZhaD2lk27XQPRJtwrABltd+UTWXcbnY/TrpxGP7VDVo=
。
如您所见,加号正在变成一个空格。这不应该发生在路径部分,只有查询部分。这就是为什么UriComponentsBuilder.build().encode()
我用来构建 URL 的 Spring 没有将加号变成%2B
.
我需要调整应用程序以使编码的斜杠 (/) 工作。有关详细信息,请参阅如果 URL 中的 ID 包含 %2F 则无法访问 REST 端点。
我正在使用 SpringBoot 1.4.4.RELEASE,它使用 Tomcat embed 8.5.11。
我曾尝试从 Spring RestTemplate、Postman 和 Chrome 调用该服务。所有情况下的结果相同,加号变成空格