簡體   English   中英

使用redmine API進行POST請求時出現401錯誤,即使我已經包含了api密鑰

[英]Getting 401 error when using redmine API for a POST request even though I have included the api key

我正在嘗試使用redmine-api創建一個新的wiki頁面。 我正在使用JavaScript和Axios。 但是我得到401錯誤(UnAuthorize)。

我的目標是能夠將單詞文檔發送到我的redmine並創建一個wiki頁面。

我正在使用提供的Api鍵,我確實在我的redmine設置中啟用了其余的api功能

我已經在標題中包含了api密鑰,但它無法正常工作。

  var wordDocument = "./Redmine.docx"

   axios.post('<website url>/uploads.json', {
    headers: {
        'Content-Type': 'application/octet-stream',
        'Cache-Control': 'no-store',
        'key': '<api-key>'
    },
    data:wordDocument

    })
    .then(function (response) { 
       console.log("succeeed--->  "); 
       console.log    (response) 
     })
    .catch(function (error) {
        console.log("failed----->  ");
        console.log(error.response.headers)
        console.log(error.message)
        console.log("failed----->  ");
    })


我獲得了一個狀態:'401 Unauthorized',

嘗試使用文檔中提到的其他身份驗證方法:

x passed in as a "key" parameter
- passed in as a username with a random password via HTTP Basic authentication
- passed in as a "X-Redmine-API-Key" HTTP header (added in Redmine 1.1.0)

https://www.redmine.org/projects/redmine/wiki/Rest_api#Authentication

還要確保使用正確的API密鑰。

登錄后,您可以在默認布局的右側窗格中的帳戶頁面(/ my / account)上找到您的API密鑰。

好吧我搞定了。 我做了“axios({})”而不是“axios.post”。 我不知道有什么不同? 我以為它是一樣的。 這是我遇到的任何人的代碼。

var wordDocument = "./Redmine.docx"
axios({
    method: 'post',
    url: '<redmind_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)
    })
.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----->  ");
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM