SpringBoot RestTemplate 访问Aliyun OSS 报错 SignatureDoesNotMatch
时间:2022-10-24 07:30:00
场景
我有一个OSS带鉴权的URL,现在需要下载. 浏览网页没问题,RestTemplate下载权限错误
异常
Exception in thread "Thread-18" org.springframework.web.client.HttpClientErrorException$Forbidden: 403 Forbidden: "
SignatureDoesNotMatch
解决
// 错误写法:这种写法会处理路径(特殊字符替换等)。)内部,使鉴权出现问题 restTemplate.exchange(imgUrl, HttpMethod.GET, httpEntity, byte[].class); // 正确的写法,使用URI包装 restTemplate.exchange(URI.create(imgUrl), HttpMethod.GET, httpEntity, byte[].class);