nacos通过api,读取和发布配置中心配置文件
String writerUrl = "http://127.0.0.1:8848/nacos/v1/cs/configs"
Map<String, String> param = new HashMap<>(6);
// 租户信息,对应 Nacos 的命名空间ID字段。
param.put("tenant", "namespace");
param.put("dataId", dataId);
param.put("group", group);
// 配置类型
param.put("type", "properties");
// 配置内容,读取配置的时候可以不要该参数
param.put("content", "XXXX");
try {
// 读取配置用GET方法
String s = HttpUtils.requestGet(writerUrl, param, null);
System.out.println(s);
// 写入配置,发布配置,用POST方法
String s = HttpUtils.requestGet(writerUrl, param, null);
System.out.println(s);
} catch (RemoteServiceException e) {
e.printStackTrace();
}