代码如下所示。
String instanceId = "ocid1.instance.oc1.eu-frankfurt-1.abtheljsmrq3yox36wukah52yaeswh6jc4vwjfkc46jxe4nwgnmga7nm7bpq";
String configurationFilePath = "~/.oci/config.txt";
String profile = "DEFAULT";
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
AuthenticationDetailsProvider provider =
new ConfigFileAuthenticationDetailsProvider(configurationFilePath, profile);
System.out.println(provider.toString());
RequestSigner requestSigner = DefaultRequestSigner.createRequestSigner(provider);
Client client =
ClientBuilder.newBuilder().build().register(new SigningFilter(requestSigner));
WebTarget target =
client.target("https://iaas.eu-frankfurt-1.oraclecloud.com")
.path("20160918")
.path("instances")
.path(UrlEscapers.urlPathSegmentEscaper().escape(instanceId));
Invocation.Builder ib = target.request();
ib.accept(MediaType.APPLICATION_JSON);
Response response = ib.get();
System.out.println(target.getUri());
我在控制台中仔细检查了实例 ocid。
输出响应如下
{ "code" : "NotAuthorizedOrNotFound", "message" : "instance ocid1.instance.oc1.eu-frankfurt-1.abtheljsmrq3yox36wukah52yaeswh6jc4vwjfkc46jxe4nwgnmga7nm7bpq not found"}
有什么输入吗?