我正在尝试使用redmine rest api创建一个Wiki页面。身份验证成功,但是由于422错误而未创建Wiki页面。
Redmine文档说:“当尝试使用无效或缺少属性参数创建或更新对象时,您将收到422 Unprocessable Entity响应。这意味着无法创建或更新对象。”
但是我似乎可以找出我的困境。当我提出第二个请求时,问题就解决了-“输入请求”。
所以我们知道问题出在那部分。
我的猜测是,它要么是文件路径,要么是内容类型。
这是我到目前为止所拥有的...
const wordDocument="C:\Users\adasani\Desktop\practice\RedmineApi/RedmineText.txt";
creatingWikiPage_Request(wordDocument);
function creatingWikiPage_Request(wordDocument) {
axios({
method: 'post',
url: '<redmine_url>/uploads.json',
headers: { 'Content-Type': 'application/octet-stream' },
params: { 'key': '<api-key>' },
data: wordDocument
})
.then(function (response) {
console.log("succeeed---> ");
console.log(response.data.upload.token)
axios({
method: 'put',
url: '<redmine_url>/projects/Testing/wiki/WikiTesting.json',
headers: { 'Content-Type': 'application/octet-stream' },
params: { 'key': '<api-key>' },
data: {
"wiki_page": {
"text": "This is a wiki page with images, and other files.",
"uploads":[
{ "token": response.data.upload.token, "filename": "RedmineText.txt", "content-type": "text/plain" }
]
}
}
})
.then(response => {
console.log("PUT is Succeed-->>>")
console.log(response)
})
.catch(error => {
console.log("Error-->>")
console.log(error.response)
})
})
.catch(function (error) {
console.log("failed-----> ");
console.log(error.response.statusText, "-->", error.response.status);
console.log(error.response.headers)
console.log(error.message)
console.log("failed-----> ");
})
}
我想看到在Redmine仪表板中创建了一个Wiki页面,但是出现422错误。
您正在将更新请求发送到JSON API,即<redmine_url>/projects/Testing/wiki/WikiTesting.json
使用Content-Type: application/octet-stream
。因此,Redmine无法解析PUTed有效负载,因为它不知道数据的格式。
为解决此问题,您应始终确保在发布数据时设置正确的内容类型。在这种情况下,将任何JSON格式的数据发送到Redmine时,应将Content-Type
标头设置为application/json
。
请注意,原则上,您可以将XML数据发送到Redmine并取回JSON。输出格式取决于以URL(.json
或.xml
)结尾的文件,您发送的数据格式始终由Content-Type
标头标识。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句