以下是api网址。不知道我是否传递了布尔值错误。我只想得到受保护的分支,但是却给了我所有的分支。
static void Main(string[] args)
{
Console.WriteLine("The stopwatch, press S to begin and Q to stop");
var UserInput = Console.ReadLine();
System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
stopWatch.Start();
switch (UserInput)
{
case "s":
stopWatch.Start();;
break;
case "q":
stopWatch.Stop();
break;
default:
Console.WriteLine("You did something wrong");
break;
}
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 2);
Console.WriteLine("RunTime " + elapsedTime);
Console.ReadLine();
}
谢谢
上面的url在删除urlencoding后起作用。 但是,当我尝试在下面的某个组织的存储库中尝试时,我得到的是什么。
"https://github.com/api/v3/repos/kpopi/Demo/branches?" + URLEncoder.encode("protected=true", "UTF-8");
下面的网址仍然有效
https://github.com/api/v3/repos/Pilliance/Dhudhu/branches?protected=true
Server:GitHub.com
Date:Thu, 28 Feb 2019 10:26:34 GMT
Content-Type:application/json; charset=utf-8
Transfer-Encoding:chunked
Status:404 Not Found
X-GitHub-Enterprise-Version:2.15.3
X-GitHub-Media-Type:github.v3; format=json
Access-Control-Expose-Headers:ETag, Link, Retry-After, X-GitHub-OTP, X-
RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes,
X-Accepted-OAuth-Scopes,
X-Runtime-rack:0.027308
{
"content": {
"message": "Not Found",
"documentation_url":
"https://developer.github.com/enterprise/2.15/v3/repos/branches/#list-branches"
}
}
答案 0 :(得分:1)
不确定我是否传递了布尔值错误。
是的,你是。您不需要此处的url编码。问题在于等号不再表示键值对(由于编码)。
答案 1 :(得分:0)
如果您查看branch api,protected
只是一个查询参数,则需要将其与API URL一起添加
https://api.github.com/repos/octocat/hello-world/branches?protected=true。这只会列出受保护的分支。
为了查看受保护的分支,您应该是存储库所有者,或者您应该对该存储库具有管理员权限。尝试检查您是否可以访问该存储库的settings
标签。
https://help.github.com/en/articles/about-protected-branches