使用XWiki REST API创建父页面子页面遇阻,求正确实现方案
使用XWiki REST API创建子页面的正确实现方案
问题回顾
在Talend tRESTClient组件中调用XWiki REST API为已有父页面创建子页面时,遇到404、405错误,甚至出现误更新父页面的情况。
正确请求格式
XWiki REST API创建子页面有两种可靠方式,对应不同的HTTP方法和URL规则:
方式一:POST请求(推荐,无需手动拼接子页面全名)
- 请求URL:
https://example.com/rest/wikis/xwiki/spaces/myspace/pages/mypage/children - 请求方法:POST
- 请求体XML:
<page xmlns="http://www.xwiki.org"> <title>My Child Page</title> <syntax>xwiki/2.1</syntax> <content>This is the content of the child page</content> </page>
说明:通过
/children后缀明确告知API要为mypage创建子页面,无需在请求体中指定<parent>字段,API会自动关联父页面。
方式二:PUT请求(需指定子页面完整名称)
- 请求URL:
https://example.com/rest/wikis/xwiki/spaces/myspace/pages/mypage.MyChildPage - 请求方法:PUT
- 请求体XML:
<page xmlns="http://www.xwiki.org"> <title>My Child Page</title> <syntax>xwiki/2.1</syntax> <parent>xwiki:myspace.mypage</parent> <content>This is the content of the child page</content> </page>
说明:XWiki中子页面的完整名称格式为
父页面名称.子页面名称,URL中需使用这个完整名称来定位要创建的子页面,同时请求体中通过<parent>字段确认父页面关联。
常见错误原因解析
- 之前尝试的
https://example.com/rest/wikis/xwiki/spaces/myspace/pages/mypage/mychildpage不符合API路径规范,XWiki REST不支持这种层级式路径,需改用.拼接或/children后缀。 - 直接PUT到父页面URL(
https://example.com/rest/wikis/xwiki/spaces/myspace/pages/mypage)会触发父页面的更新操作,这是路径指向错误导致的。 - 404错误多因URL格式不匹配API规则,405错误则是对不支持对应HTTP方法的路径使用了错误方法。
内容的提问来源于stack exchange,提问作者Lucas
相关产品推荐
相关产品推荐

