我打算實現一個Java客戶端部署和取消部署應用程序到GlassFish,Glassfish的REST API
下面是CURR命令
curl -s -S \
-H 'Accept: application/json' \
-H 'X-Requested-By: dummy' \
-X DELETE http://localhost:4848/management/domain/applications/application/hello
我的Java代碼
URL url = new URL(
"http://localhost:4851/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
String input = "{\"DELETE\":\"http://localhost:4851/management/domain/applications/application/hello\"}";
OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();
if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
不幸的是,我無法獲得預期的結果。 任何人都可以提供建議嗎?
可怕的問題。什麼是預期的結果,你會得到什麼,而你有什麼嘗試等等等等等等 – thecoshman