使用令牌从私有github存储库下载字符串

时间:2017-02-07 03:32:36

标签: c# curl github

我需要在Private Github存储库中获取单个文件的内容,但我的问题是我无法找到一种方法使我的代码能够用于github身份验证:

我在Github API上发现我可以做一个CURL请求但是我不知道如何在C#上做一个卷曲

            curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com
            curl https://api.github.com/?access_token=OAUTH-TOKEN

            var client = new HttpClient();

            // Create the HttpContent for the form to be posted.
            var requestContent = new FormUrlEncodedContent(new[] {
                new KeyValuePair<string, string>("access_token", "keeeeeeeeeeeeeeeeeeeeeeeeeeeeey"),
            });

            // Get the response.
            HttpResponseMessage response = await client.PostAsync(
                "https://raw.githubusercontent.com/user/repo/master/file.text",
                requestContent);

            // Get the response content.
            HttpContent responseContent = response.Content;

            // Get the stream of the content.
            using (var reader = new StreamReader(await responseContent.ReadAsStreamAsync()))
            {
                // Write the output.
                Console.WriteLine(await reader.ReadToEndAsync());
            }

任何想法?

0 个答案:

没有答案