解决eureka开启basic时请求无权限问题

pull/13/head
chengzi 3 years ago
parent e1cc2c982d
commit 7b930fa4b8
  1. 14
      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() {

Loading…
Cancel
Save