1

当我提交 REST 请求时,例如:(包含的身份验证适用于 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 方法检查命令参数,它们都是可选的。

4

2 回答 2

4

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

添加、更新或删除对象的 REST 请求必须指定 X-Requested-By 标头,其值为“GlassFish REST HTML 接口”。

所以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
于 2013-07-17T10:49:27.123 回答
0

根据上面的答案,针对那些尝试使用 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
于 2019-12-17T17:38:07.760 回答