mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
!13 解决 eureka 配置 security 时请求 401 无权限问题
Merge pull request !13 from 程子/pr
This commit is contained in:
@@ -5,6 +5,8 @@ import okhttp3.Request;
|
|||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.internal.http.HttpMethod;
|
import okhttp3.internal.http.HttpMethod;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
|
* https://github.com/Netflix/eureka/wiki/Eureka-REST-operations
|
||||||
*
|
*
|
||||||
@@ -64,12 +66,16 @@ public enum EurekaUri {
|
|||||||
url = url.substring(0, url.length() - 1);
|
url = url.substring(0, url.length() - 1);
|
||||||
}
|
}
|
||||||
String requestUrl = url + getUri(args);
|
String requestUrl = url + getUri(args);
|
||||||
Request request = this.getBuilder()
|
Request.Builder builder = this.getBuilder()
|
||||||
.url(requestUrl)
|
.url(requestUrl)
|
||||||
.addHeader("Content-Type", "application/json")
|
.addHeader("Content-Type", "application/json")
|
||||||
.addHeader("Accept", "application/json")
|
.addHeader("Accept", "application/json");
|
||||||
.build();
|
//是否开启 Basic
|
||||||
return request;
|
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() {
|
public Request.Builder getBuilder() {
|
||||||
|
Reference in New Issue
Block a user