我想连接gitlab api以获得最近的一些提交。它在curl中工作,但是ajax调用失败。
我从服务器获得状态代码401:
SELECT Name, Date AND price FROM table 1 INNER JOIN table 2 ON table1.key=table2.fktable1
标题中的私人令牌似乎是正确的,所以我不知道问题可能是什么。谢谢你的帮助!
{"message":"401 Unauthorized"}
请求代码:
:authority: gitlab.example.de (changed to example domain)
:method: GET
:path: /api/v4/projects/83/repository/commits
:scheme: https
accept: */*
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
cache-control: no-cache
content-type: json
origin: http://labtime.local
pragma: no-cache
private-token: [my token]
referer: http://labtime.local/?
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36
答案 0 :(得分:0)
请考虑尝试此
var settings = {
"async": true,
"crossDomain": true,
"url": https://gitlab.example.de/api/v4/projects/"+id+"/repository/commits,
"method": "GET",
"headers": {
"PRIVATE-TOKEN": "TOKEN"
}
}
$.ajax(settings).done(function (response) {
console.log(response);
});
注意:只需验证一次是否在URL中获得了正确的值。我已经为用户测试了它,它对我来说运行正常。