因为需要对接kubesphere的接口
请求接口地址:http://10.31.121.201:30880/apis/apps/v1/namespaces/{namespace}/deployments
请求方式:
public static JSONObject httpPostRequest(String param,String url,String token){
JSONObject jsonObject = new JSONObject();
HttpClient httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();
try{
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url)).header(“Content-Type”,“application/yaml”)
.header(“Authorization”,“Bearer ”+token)
.POST(HttpRequest.BodyPublishers.ofString(param)).build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}catch (Exception e){
e.printStackTrace();
}
return jsonObject;
}
报错信息:
Caused by: java.net.URISyntaxException: Illegal character in path at index 51: http://10.31.121.201:30880/apis/apps/v1/namespaces/{namespace}/deployments
个人尝试:
String encodedUserid = URLEncoder.encode(“{”+“namespace”+“}”,“UTF-8”);
均不能访问kubesphere的api接口,请问有什么好解决办法么