简体   繁体   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

I am trying to make a post request to create a new wiki page using the redmine-api. 我正在尝试使用redmine-api创建一个新的wiki页面。 I am using JavaScript and Axios. 我正在使用JavaScript和Axios。 However I a getting a 401 error(UnAuthorize). 但是我得到401错误(UnAuthorize)。

My goal is to be able to send a word document to my redmine and create a wiki page. 我的目标是能够将单词文档发送到我的redmine并创建一个wiki页面。

I am using the Api key provided and I did enable the rest api feature in my redmine setting 我正在使用提供的Api键,我确实在我的redmine设置中启用了其余的api功能

I have included the api key in the header however it is not working. 我已经在标题中包含了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----->  ");
    })


I am getting a status: '401 Unauthorized', 我获得了一个状态:'401 Unauthorized',

Try using the other authentication methods mentioned in the docs: 尝试使用文档中提到的其他身份验证方法:

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 https://www.redmine.org/projects/redmine/wiki/Rest_api#Authentication

Also ensure that you're using the correct API key. 还要确保使用正确的API密钥。

You can find your API key on your account page ( /my/account ) when logged in, on the right-hand pane of the default layout. 登录后,您可以在默认布局的右侧窗格中的帐户页面(/ my / account)上找到您的API密钥。

Alright I got it working. 好吧我搞定了。 I did "axios({})" instead of "axios.post". 我做了“axios({})”而不是“axios.post”。 I do not know what the different is? 我不知道有什么不同? I thought it was the same. 我以为它是一样的。 Here is my code for anyone who run into this.\\ 这是我遇到的任何人的代码。

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.

相关问题 pdflayer API发布请求说我没有提供api_key,即使它提供了 - pdflayer API post request saying I didnt not provide api_key even though it did 尝试使用其 API 在 Spotify 中创建播放列表时出现“请求失败,状态代码 401”错误 - Getting "Request failed with status code 401" error when trying to create a playlist in Spotify using their API 即使我添加了请求模块,也会收到“错误:找不到模块‘请求’” - Getting "Error: Cannot find module 'request'" even though I have added request module 错误 401:未经授权,即使在使用 www.openweathermap.org 时使用 API 密钥也会收到 - error 401 : unauthorized, received even after using API key while using www.openweathermap.org 即使密钥有效,Razorpay API 也会出现无效密钥错误 - Razorpay API gives inavlid key error even though the key is valid 即使我拥有正确的身份验证密钥,Google 地图 API 也没有显示我的地图 - Google map API is not displaying my map even though I have the correct authentication key 即使我传递了 api 令牌,请求也失败,状态代码为 401 - Request failed with status code 401 even when I passed the api token 使用 OMDB API 时如何修复 401 错误? - How do I fix 401 error when using OMDB API? Ionic 3 WP-REST API发布请求401(未经授权)错误 - Ionic 3 WP-REST API Post request 401 (unauthorized) error React 和 Redux: 401 Unauthorized Error POST API 请求 - React and Redux: 401 Unauthorized Error POST API Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM