我正在尝试使用gitlab api从我的仓库中获取文件,但没有成功。你能给我一些指导吗?当我运行下面的C#代码时,会收到此响应
{
“message”: “Access forbidden. Check your access level.”,
“documentation_url”: “https://gitlab.com/help”
}
我很确定自己通过了正确的认证。 C#代码如下:
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/vnd.git-lfs+json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
System.Text.ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", <my_username>, <my_password>))));
string json = @"{
'operation': 'download',
'transfers': [ 'basic' ],
'ref': { 'name': 'refs/heads/master' },
'objects': [
{
'oid': '9669a62bbe8d8150c11d814509078b5db8f73c97ecfc94beb1dc6b22130adf7b',
'size': 4465559,
'authenticated': true
}
]
}";
var response = client.PostAsync("https://gitlab.com/<my_repo>/info/lfs/objects/batch", new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json"));