0

I'm having an a 403 response when I try to get the content of a repo on GitHub.

Using a curl command " curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer <my_token>" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/Arcadix/Product.Fusion/contents" gives me the right content, but using C# I get a 403 error. Here is the code:

var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "token123"); //token123 is replaced by my token of course
httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.github+json");
httpClient.DefaultRequestHeaders.Add("X-GitHub-Api-Version", "2022-11-28");
var contentsUrl = $"https://api.github.com/repos/Arcadix/Product.Fusion/contents";
var contentsJson = httpClient.GetStringAsync(contentsUrl).Result;
Console.WriteLine(contentsJson);

0 Answers0