GitHub使用cURL重定向



我试图通过cURL在gitHub中创建一个repo。然而,每当我试图创建repo时,它都会通过重定向给我登录URL,我无法从那里继续操作。也不能让我选择插入我的凭据。我正在使用我的访问令牌登录。不知道我该怎么做。

下面是我正在尝试的cURL:

curl -H "Authorization: token" -k https://enterprise.github.com/orgs/internal/repositories -d '{"name": "testRepo", "description": "my test repo", "private":true}'

我总是得到以下回复:

<html><body>You are being <a href="https://enterprise.github.com/login?return_to=https%3A%2F%2Fenterprise.github.com%2Forgs%2Finternal%2Frepositories">redirected</a>.</body></html>

我无法弄清楚的是,我如何从这里登录,为什么当我使用访问令牌登录时,我必须再次登录?我也尝试过在cURL中使用-L,但这也没有帮助。

问题是您访问的是web界面而不是API。出于安全原因,令牌不允许访问web界面。

对于GitHub Enterprise Server实例,根据其配置方式,您需要访问https://api.enterprise.github.comhttps://enterprise.github.com/api/v3下的内容,具体取决于实例的配置方式。也就是说,URL应该是https://api.enterprise.github.com/orgs/internal/repositorieshttps://enterprise.github.com/api/v3/orgs/internal/repositories

所以我可以通过使用下面的cURL来解决重定向问题。然而,现在我看到了";必须启用Cookie才能使用GitHub"消息作为来自以下cURL:的响应

curl 
-X POST 
-H "Accept: application/vnd.github+json" 
-H "Authorization: Bearer access token" 
-k -L --post302 https://enterprise.github.com/orgs/internal/repositories 
-d '{"name": "testRepo", "description": "my test repo", "private":true}'

如何摆脱这些Cookie必须启用才能使用GitHub。错误

最新更新