我使用Octokit.net version 0.9.0 (GitHub API for .NET)获取少数存储库的压缩内容。
我已经有了我需要的存储库列表,但是我在将存储库的内容作为.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;我的尝试有问题
data为空responseData.GetType().Name说responseData是字符串类型的Encoding.ASCII.GetBytes(response.HttpResponse.Body.ToString());时,我会得到无效的zip文件

奎泽
使用Octokit.net库进行身份验证后,获得存储库压缩球的正确方法是什么?
我还在问题存储库中打开了octokit.net。
发布于 2015-04-27 16:55:53
在检查了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 (contentType == null || (!contentType.StartsWith("image/") && !contentType.StartsWith("application/")))替换if语句)来修复这个问题(然后是一个字节数组)。(可以使用System.IO.File.WriteAllBytes("c:\\test.zip", (byte[])responseData);编写)。
https://stackoverflow.com/questions/29766916
复制相似问题