3

我正在使用Octokit.net version 0.9.0 (GitHub API for .NET) 来获取少数存储库的 zip 内容。

我已经有了我需要的存储库列表,但是我无法将存储库的内容作为 .zip 文件(称为 zipball)

到目前为止我尝试过的

// ... client = new Client(...);
// some authentication logic...
// some other queries to GitHub that work correctly
var url = "https://api.github.com/repos/SomeUser/SomeRepo/zipball";
var response = await this.client.Connection.Get<byte[]>(
        new Uri(url),
        new Dictionary<string, string>(),
        null);
var data = response.Body;
var responseData = response.HttpResponse.Body;

我的尝试有问题

  1. data一片空白
  2. responseData.GetType().NameresponseData是字符串类型
  3. 当我尝试时,Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString());我得到了无效的 zip 文件

response.HttpResponse.Body 的值

问题

使用 Octokit.net 库进行身份验证后获取存储库 zipball 的正确方法是什么?

我还在octokit.net 存储库中打开了一个问题。

4

1 回答 1

2

检查 Octokit 的来源后,我认为这是不可能的(从 0.10.0 版开始):

请参阅Octokit\Http\HttpClientAdapter.cs

// We added support for downloading images. Let's constrain this appropriately.
if (contentType == null || !contentType.StartsWith("image/"))
{
    responseBody = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
}
else
{
    responseBody = await responseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
}

响应正文 ( responseData) 被转换为一个 unicode 字符串,因此,它被破坏而不是二进制。请参阅我的PR792(需要将 if 语句替换为if (contentType == null || (!contentType.StartsWith("image/") && !contentType.StartsWith("application/"))))来解决此问题(然后它是一个字节数组。可以使用 编写System.IO.File.WriteAllBytes("c:\\test.zip", (byte[])responseData);)。

于 2015-04-27T16:55:53.327 回答