我使用 netcat 捕获了以下数据
root@gitlab_new:/curl_hacks# nc -lp 5555
POST /project/PROJECT_ID HTTP/1.1
Content-Type: application/json
X-Gitlab-Event: Push Hook
Authorization: Basic VVNFUl9JRDpUT0tFTl9JRA==
Connection: close
Host: localhost:5555
Content-Length: 1968
{"object_kind":"push","event_name":"push","before":"87257922812b7ce1e84f2ff4a74f9548e7b521ff","after":"84f95fb521fe48b357b6556f755b177fc9793d6c","ref":"refs/heads/master","checkout_sha":"84f95fb521fe48b357b6556f755b177fc9793d6c","message":null,"user_id":1,"user_name":"Administrator","user_username":"root","user_email":"admin@example.com","user_avatar":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","project_id":1,"project":{"id":1,"name":"hello-world","description":"","web_url":"http://gitlab_new/root/hello-world","avatar_url":null,"git_ssh_url":"git@gitlab_new:root/hello-world.git","git_http_url":"http://gitlab_new/root/hello-world.git","namespace":"root","visibility_level":0,"path_with_namespace":"root/hello-world","default_branch":"master","ci_config_path":null,"homepage":"http://gitlab_new/root/hello-world","url":"git@gitlab_new:root/hello-world.git","ssh_url":"git@gitlab_new:root/hello-world.git","http_url":"http://gitlab_new/root/hello-world.git"},"commits":[{"id":"84f95fb521fe48b357b6556f755b177fc9793d6c","message":" M commit_history\n","timestamp":"2018-07-16T16:03:39+02:00","url":"http://gitlab_new/root/hello-world/commit/84f95fb521fe48b357b6556f755b177fc9793d6c","author":{"name":"wakatana","email":"wakatana@topsecretmail.gov"},"added":[],"modified":["commit_history"],"removed":[]},{"id":"87257922812b7ce1e84f2ff4a74f9548e7b521ff","message":"1 commit\n","timestamp":"2018-07-16T12:55:13+02:00","url":"http://gitlab_new/root/hello-world/commit/87257922812b7ce1e84f2ff4a74f9548e7b521ff","author":{"name":"wakatana","email":"wakatana@topsecretmail.gov"},"added":["commit_history"],"modified":[],"removed":[]}],"total_commits_count":2,"repository":{"name":"hello-world","url":"git@gitlab_new:root/hello-world.git","description":"","homepage":"http://gitlab_new/root/hello-world","git_http_url":"http://gitlab_new/root/hello-world.git","git_ssh_url":"git@gitlab_new:root/hello-world.git","visibility_level":0}}root@gitlab_new:/curl_hacks#
这些数据是通过 GitLab 发送的。在这里,它们以(更漂亮的)形式显示,我可以通过 GitLab 网络界面看到它:
请求网址:
POST http://USER_ID:TOKEN_ID@localhost:5555/project/PROJECT_ID
请求标头:
Content-Type: application/json
X-Gitlab-Event: Push Hook
请求正文:
{
"object_kind": "push",
"event_name": "push",
"before": "87257922812b7ce1e84f2ff4a74f9548e7b521ff",
"after": "84f95fb521fe48b357b6556f755b177fc9793d6c",
"ref": "refs/heads/master",
"checkout_sha": "84f95fb521fe48b357b6556f755b177fc9793d6c",
"message": null,
"user_id": 1,
"user_name": "Administrator",
"user_username": "root",
"user_email": "admin@example.com",
"user_avatar": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"project_id": 1,
"project": {
"id": 1,
"name": "hello-world",
"description": "",
"web_url": "http://gitlab_new/root/hello-world",
"avatar_url": null,
"git_ssh_url": "git@gitlab_new:root/hello-world.git",
"git_http_url": "http://gitlab_new/root/hello-world.git",
"namespace": "root",
"visibility_level": 0,
"path_with_namespace": "root/hello-world",
"default_branch": "master",
"ci_config_path": null,
"homepage": "http://gitlab_new/root/hello-world",
"url": "git@gitlab_new:root/hello-world.git",
"ssh_url": "git@gitlab_new:root/hello-world.git",
"http_url": "http://gitlab_new/root/hello-world.git"
},
"commits": [
{
"id": "84f95fb521fe48b357b6556f755b177fc9793d6c",
"message": " M commit_history\n",
"timestamp": "2018-07-16T16:03:39+02:00",
"url": "http://gitlab_new/root/hello-world/commit/84f95fb521fe48b357b6556f755b177fc9793d6c",
"author": {
"name": "wakatana",
"email": "wakatana@topsecretmail.gov"
},
"added": [
],
"modified": [
"commit_history"
],
"removed": [
]
},
{
"id": "87257922812b7ce1e84f2ff4a74f9548e7b521ff",
"message": "1 commit\n",
"timestamp": "2018-07-16T12:55:13+02:00",
"url": "http://gitlab_new/root/hello-world/commit/87257922812b7ce1e84f2ff4a74f9548e7b521ff",
"author": {
"name": "wakatana",
"email": "wakatana@topsecretmail.gov"
},
"added": [
"commit_history"
],
"modified": [
],
"removed": [
]
}
],
"total_commits_count": 2,
"repository": {
"name": "hello-world",
"url": "git@gitlab_new:root/hello-world.git",
"description": "",
"homepage": "http://gitlab_new/root/hello-world",
"git_http_url": "http://gitlab_new/root/hello-world.git",
"git_ssh_url": "git@gitlab_new:root/hello-world.git",
"visibility_level": 0
}
}
如何使用 curl 重新发送这些数据?我试过以下(header.json 和 body.json 是从 GitLab Web 界面复制的):
root@lubuntu18-64:~/curl_hacks# curl --head @header.json --data @body.json http://USER_ID:TOKEN_ID@localhost:5555/project/PROJECT_ID
Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and HEAD (-I, --head).
据我了解,问题是 --head 和 --data 不能一起使用,但根据 GitLab 输出,我需要同时使用它们,因为有些是标题,有些是数据。我错过了什么?谢谢