这是我的示例curl
命令。
curl -v -X GET "https://example.com/keyword.json?a=1&b=2" --data-urlencode "example=another language"
我对GET
发出了RestTemplate
请求,如下所示:
public class Example {
public void start(String url) {
RestTemplate restTemplate = new RestTemplate();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url)
.queryParam("a", 1)
.queryParam("b", 2)
.queryParam("example", "another language")
.encode(StandardCharsets.UTF_8);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
ResponseEntity<String> responseEntity = restTemplate.exchange(
builder.toUriString(),
HttpMethod.GET,
new HttpEntity<>(httpHeaders),
String.class
);
}
}
问题是,我想用其他语言(而不是英语)发送示例参数--url-encoded
,但编码格式不正确。
如何正确处理?