使用Tampermonkey,我想在HCL Connections 6.6的现有wiki中创建一个wiki页面。根据文件我建立了这个函数。
function createWikiPage(cnxBase) {
let wikiLabel = 'API Test Wiki'
let url = `${cnxBase}/wikis/basic/api/wiki/${wikiLabel}/feed`
let body = `
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text">Matt's Page6</title>
<summary type="text">My test</summary>
<content type="text">This is James's wiki page.</content>
<category term="wikipagetag1" />
<category term="wikipagetag2" />
<category term="wikipagetag3" />
<category scheme="tag:ibm.com,2006:td/type" term="page" label="page" />
</entry>
`
let args = {
method: "POST",
url: url,
data: body,
headers: {
"Content-Type": "application/atom+xml"
},
onload: function(response) {
alert(response.status + ' ' + response.responseText);
}
}
GM_xmlhttpRequest(args)
}
调用这个函数后,带有标签的wiki页面被创建了 createWikiPage('https://cnx-host')
但没有任何内容。此外,当我在浏览器中编辑页面并切换到 html源码 内容中看不到任何字符。
为什么官方的例子不能用?
我发现在正文中需要一些额外的数据(主要是使用 CDATA
而这并没有记录在案。下面的条目给了我正确的提示。https:/andydunkel.net20170830use-c-to-post-to-ibm-connections-blogs-and-wikis。
function createWikiPage(wikiLabel, title, text) {
let url = `${cnxBase}/wikis/basic/api/wiki/${wikiLabel}/feed`
console.log(`Post to ${url}`)
let body = `
<entry xmlns="http://www.w3.org/2005/Atom">
<category term="page" label="page" scheme="tag:ibm.com,2006:td/type"></category>
<label xmlns="urn:ibm.com/td">${title}</label>
<category term="etherpad" />
<category term="notizen" />
<category term="entwurf" />
<content type="text/html"><![CDATA[<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html [<!ENTITY amp
"&#38;"><!ENTITY lt "<#60;"><!ENTITY gt
">#62;"><!ENTITY nbsp " "><!ENTITY apos
"'"><!ENTITY quot """>]><div>${text}</div>]]></content>
</entry>`
let args = {
method: "POST",
url: url,
data: body,
headers: {
"Content-Type": "application/atom+xml"
},
onload: function (response) {
// ToDo: Return status
alert(response.status + ' ' + response.responseText);
console.log(response.responseText)
}
}
GM_xmlhttpRequest(args)
}