From 7b930fa4b8d55727503324fa7410bcd821682fb7 Mon Sep 17 00:00:00 2001 From: chengzi <395030787@qq.com> Date: Mon, 14 Mar 2022 11:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3eureka=E5=BC=80=E5=90=AFbasic?= =?UTF-8?q?=E6=97=B6=E8=AF=B7=E6=B1=82=E6=97=A0=E6=9D=83=E9=99=90=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sop/adminserver/service/impl/EurekaUri.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/impl/EurekaUri.java b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/impl/EurekaUri.java index a3a20805..5b53b11d 100644 --- a/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/impl/EurekaUri.java +++ b/sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/impl/EurekaUri.java @@ -5,6 +5,8 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.internal.http.HttpMethod; +import java.util.Base64; + /** * https://github.com/Netflix/eureka/wiki/Eureka-REST-operations * @@ -64,12 +66,16 @@ public enum EurekaUri { url = url.substring(0, url.length() - 1); } String requestUrl = url + getUri(args); - Request request = this.getBuilder() + Request.Builder builder = this.getBuilder() .url(requestUrl) .addHeader("Content-Type", "application/json") - .addHeader("Accept", "application/json") - .build(); - return request; + .addHeader("Accept", "application/json"); + //是否开启 Basic + if(url.contains("@") && url.contains(":")){ + String user = url.split("@")[0].replace("http://","").replace("https://",""); + builder.addHeader("Authorization","Basic " + Base64.getUrlEncoder().encodeToString(user.getBytes())); + } + return builder.build(); } public Request.Builder getBuilder() {