我正在使用 REST 模板有意在请求 uri 中发送 %,例如/items/a%b
String responseEntity = restTemplate.exchange("/items/a%b",
requestObj.getHttpMethod(), requestEntity, String.class);
The restTemplate
正在转换此 uri 的结尾,它正在变成/items/a%25b
这是有道理的,因为其余模板默认对 uri 进行编码。
我尝试使用UriComponent
用于禁用 uri 的编码
UriComponents uriComponents = UriComponentsBuilder.fromPath("/items/a%b").build();
URI uri= uriComponents.toUri();
String responseEntity = restTemplate.exchange(uri,
requestObj.getHttpMethod(), requestEntity, String.class);
但这不起作用,因为 uri 又是执行编码的 URI 类型。我确信我没有以正确的方式使用 UriComponents。
如果有人能指出禁用编码的正确方法是什么,我将非常感激。
Thanks.
来自 UriComponentsBuilder 文档,存在方法build(boolean encoded)
build(boolean encoded)
从构建 UriComponents 实例
该构建器中包含的各种组件。
UriComponents uriComponents = UriComponentsBuilder.fromPath("/items/a%b").build(true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)