为什么我不能通过REST API启用或禁用我的GlassFish应用程序?

时间:2013-07-17 10:49:27

标签: glassfish glassfish-3

当我提交REST请求时,EG :(包含auth用于admin / adminadmin)

curl -ik -X POST -H "Accept: application/json"
  -H "Authorization: Basic YWRtaW46YWRtaW5hZG1pbg=="
  https://localhost:4848/management/domain/applications/application/MyApp/enable

GlassFish只是拒绝请求:

HTTP/1.1 400 Bad Request
Content-Length: 0
Date: Wed, 17 Jul 2013 10:33:06 GMT
Connection: close

我做错了什么?

我使用GET方法检查命令参数,它们都是可选的。

2 个答案:

答案 0 :(得分:3)

来自:http://docs.oracle.com/cd/E26576_01/doc.312/e24928/general-administration.htm

  

添加,更新或删除对象的REST请求必须使用值“GlassFish REST HTML interface”指定X-Requested-By标头。

所以EG:

curl -ik -X POST -H "Accept: application/json"
  -H "Authorization: Basic YWRtaW46YWRtaW5hZG1pbg=="
  -H "X-Requested-By: GlassFish REST HTML interface"
  https://localhost:4848/management/domain/applications/application/MyApp/enable

答案 1 :(得分:0)

基于answer above,针对那些尝试与Glassfish的后继产品-Payara Server一起使用的人进行了调整:

启用应用

curl -ik -X POST \
  -H 'accept: application/json;charset=UTF-8' \
  -H 'authorization: Basic YWRtaW46YWRtaW5hZG1pbg==' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'x-requested-by: GlassFish REST HTML interface' \
  --data target=server \
  --url https://localhost:4848/management/domain/applications/application/awesomeApp/enable 

禁用应用

curl -ik -X POST \
  -H 'accept: application/json;charset=UTF-8' \
  -H 'authorization: Basic YWRtaW46YWRtaW5hZG1pbg==' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -H 'x-requested-by: GlassFish REST HTML interface' \
  --data target=server \
  --url https://localhost:4848/management/domain/applications/application/awesomeApp/disable
相关问题