可以使用以下代码示例解决这个问题:
AmazonHttpClient client = new AmazonHttpClient(new ClientConfiguration());
URI endpoint = URI.create("https://example.endpoint.com");
String path = "/api/resource";
// Remove trailing slash from path
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
HttpGet httpGet = new HttpGet(endpoint.resolve(path));
client.execute(httpGet);
代码中,我们手动将请求路径中的尾随斜杠去掉,再使用 resolve 方法将 endpoint 和 path 拼成最终的 URL。这样就可以避免 AmazonHttpClient 在 URL 中添加额外的斜杠了。
下一篇:Amazon会话令牌