dyc87112 / spring-cloud-config-admin

Spring Cloud Config的综合管理后台(简称:SCCA)

Home Page:https://dyc87112.github.io/spring-cloud-config-admin-doc/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

http://user:password@localhost:8761/eureka/,这种形式的eureka,会报401错误

innerpeacez opened this issue · comments

commented

Basic之后的Eureka,通过UrlMaker4Eureka解析报org.springframework.web.client.HttpClientErrorException: 401 null。

我这边的两种解决办法

image

private String getConfigInfoHeader(String url) { if (url.contains("@")) { String authStr = url.substring(url.indexOf("//") + 2, url.indexOf("@")); String[] auth = authStr.split(":"); String auth_Str = auth[0] + ":" + auth[1]; byte[] encodedAuth = Base64.encodeBase64(auth_Str.getBytes(Charset.forName("US-ASCII"))); String authHeader = "Basic " + new String(encodedAuth); HttpHeaders headers = new HttpHeaders(); headers.set("authorization", authHeader); return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(null, headers), String.class).getBody(); } else { return restTemplate.getForObject(url, String.class); } }

private String getConfigInfo(String url) { if (url != null && url.contains("@")) { RestTemplate restTemplate = new RestTemplate(); String authStr = url.substring(url.indexOf("//") + 2, url.indexOf("@")); String[] auth = authStr.split(":"); restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(auth[0], auth[1])); return restTemplate.getForObject(url, String.class); } // 访问eureka接口获取一个可以访问的实例 return this.restTemplate.getForObject(url, String.class); }

commented

image

commented

image

@innerpeacez 感谢建议,可以提交一个PR吗?

我已经提交了PR了@dyc87112