首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法以.zip文件(zipball)的形式在Octokit.net中获取存储库内容

无法以.zip文件(zipball)的形式在Octokit.net中获取存储库内容
EN

Stack Overflow用户
提问于 2015-04-21 08:33:34
回答 1查看 754关注 0票数 3

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

我已经有了我需要的存储库列表,但是我在将存储库的内容作为.zip文件(称为zipball)时遇到了困难。

到目前为止我尝试过的

代码语言:javascript
复制
// ... 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文件

奎泽

使用Octokit.net库进行身份验证后,获得存储库压缩球的正确方法是什么?

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-27 16:55:53

在检查了Octokit的源代码之后,我认为这是不可能的(从0.10.0版起):

请参阅Octokit\Http\HttpClientAdapter.cs

代码语言:javascript
复制
// 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 (contentType == null || (!contentType.StartsWith("image/") && !contentType.StartsWith("application/")))替换if语句)来修复这个问题(然后是一个字节数组)。(可以使用System.IO.File.WriteAllBytes("c:\\test.zip", (byte[])responseData);编写)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29766916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档