Gitlab使用Axios或Curl请求发布/放入节点 - 无法写入资源 - 400错误

问题描述 投票:4回答:1

当使用Gitlab api时,我似乎无法发布任何内容,除非它的"Content-Type": "text/plain"。我也尝试了一个curl请求,我可以使用GET,但也没有运气POST / PUT。

我经历了并确保尽可能公开访问,检查是否有公钥,等等仍然没有运气。

作品

let url = window.djConfig.DJ_URL + "api/v1/git" + "/project/directory";
 axios.put(url, 'stuff',{
  headers: {
    "Content-Type": "text/plain"
   }
  })
  .then(function (res) {
    //do success stuff
  })
  .catch(function (err) {
    //do error stuff
 })

curl --request GET --header 'PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU' 'https://gitlab.example.com/api/v4/git/journey-content/bower%2Ejson?ref=master'

但是,如果我尝试做任何更强大的事情,比如添加提交消息,我会得到错误:

{"message":"Unable to write resource.","status":400}

我有更强大的Axios设置

不行

let url = window.djConfig.DJ_URL + "api/v1/git" + "/project/directory";
let commit = {
  file_path: 'project/directory',
  branch: 'master',
  content: '{key: "value"}',
  commit_message: 'test commit'
}

axios.put(url, commit,{
   headers: {
    "Content-Type": "application/json"
   }
})
.then(function (res) {
   // do success stuff
})
.catch(function (err) {
  // do error stuff
})


curl --request POST --header 'PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU' 'http://localhost:8911/developerjourney/api/v1/git/journey-content/projectrb%2E?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20content&commit_message=create%20a%20new%20file'

我喜欢Gitlab如何提供这个无用的信息......

如果提交因任何原因失败,我们将返回400错误,并显示非特定错误消息。提交失败的可能原因包括:

file_path包含/../(尝试目录遍历);新文件内容与当前文件内容相同,即用户尝试进行空提交;文件编辑正在进行时,分支由Git push更新。目前gitlab-shell有一个布尔返回码,阻止GitLab指定错误。

不知道我错过了什么,但如果我能得到但不发布/放置,感觉就像权限一样。

如果我使用--verbose发出请求,这里是终端的完整输出

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8911 (#0)
> POST /developerjourney/api/v1/git/journey-content/projectrb%2E?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20content&commit_message=create%20a%20new%20file HTTP/1.1
> Host: localhost:8911
> User-Agent: curl/7.54.0
> Accept: */*
> PRIVATE-TOKEN: ycEKE_uSQiRXzMtrZuZU
> 
< HTTP/1.1 400 Bad Request
< X-Powered-By: Express
< X-DJ-Redirect-URL: http://localhost:8911/developerjourney/authenticate
< X-DJ-GitLab-Host: https://localhost:30443
< X-DJ-GitLab-Path: 
< X-DJ-GitLab-Application-Id: 513ce27b4c730d461fa68ceae3eab23f726dc975c3d250de79af8d301f74f4f7
< X-DJ-JourneyGroup: journeys
< X-DJ-URL: http://localhost:8911/developerjourney/
< Set-Cookie: dj-session=18245958cb989b009e7417d76b62331a; Max-Age=1209600; Path=/; Expires=Fri, 05 Jan 2018 19:46:56 GMT; HttpOnly
< Content-Type: application/json; charset=utf-8
< Content-Length: 52
< ETag: W/"34-mpqGlVzme26p5gWU36ILGyMDScQ"
< Date: Fri, 22 Dec 2017 19:46:56 GMT
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
{"message":"Unable to write resource.","status":400}

使用v4 api

如果您使用以下代码段

curl --request POST --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'http://localhost:8911/developerjourney/api/v4/projects/2/journey-content/app%2Fprojectrb%2E?branch=master&content=some%20content&commit_message=create%20a%20new%20file'

我在HTML中返回错误文本。 “旅程内容”是我的项目名称,在名为“旅程”的组中

javascript node.js gitlab axios
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.