如何使用API​​从gitlab存储库中提取LFS文件

时间:2018-11-02 05:44:14

标签: c# api gitlab

我正在尝试使用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"));

0 个答案:

没有答案