以下curl
命令在CRX中创建一个节点:
curl -u admin:admin \
-F”jcr:primaryType=nt:unstructured” \
-F”sling:resourceType=foo/bar” ... http://localhost:4502
然而,CQ5以HTML格式返回响应:
<html>
<head>
<title>Content modified ...</title>
</head>
<body>
<h1>Content modified ...</h1>
...
<p><a href="">Go Back</a></p>
<p><a href="...">Modified Resource</a></p>
<p><a href="/etc/tags/...-keywords">Parent of Modified Resource</a></p>
</body>
</html>
有没有办法制作请求,以便响应采用JSON格式?
答案 0 :(得分:3)
Apache Sling根据请求的Accept标头选择输出格式:
$ curl -u admin:admin -s -H"Accept:application/json" -Ftest=ok http://localhost:8080/tmp | jq .
{
"referer": "",
"changes": [
{
"argument": "/tmp",
"type": "created"
},
{
"argument": "/tmp/test",
"type": "modified"
}
],
"path": "/tmp",
"location": "/tmp",
"parentLocation": "/",
"isCreate": true,
"status.code": 201,
"status.message": "Created",
"title": "Content created /tmp"
}
这应该在CQ中起作用。
根据Sling的PostServletOutputContentTypeTest,您还可以使用:http-equiv-accept
请求参数代替Accept标头。