0
我能够使用curl获取github发布详细信息,但我想使用php来执行此操作。如何使用php-curl(凭据)从github获取发布信息?
我在卷曲使用的命令如下:
curl -u user.ca:password -X GET https://api.github.com/repos/xyz/abc/releases
我能够使用curl获取github发布详细信息,但我想使用php来执行此操作。如何使用php-curl(凭据)从github获取发布信息?
我在卷曲使用的命令如下:
curl -u user.ca:password -X GET https://api.github.com/repos/xyz/abc/releases
PHP的当量-u
选项是CURLOPT_USERPWD
。
curl_setopt($ch, CURLOPT_USERPWD, 'user.ca:password');
你到底会是这样的:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/xyz/abc/releases");
curl_setopt($ch, CURLOPT_USERPWD, 'user.ca:password');
curl_setopt($ch, CURLOPT_USERAGENT,'Awesome-Octocat-App');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$fetch = curl_exec($ch);
curl_close($ch);
以及如何打印输出? 我试过打印$ fetch并得到了 请求被管理规则禁止。请确保您的请求具有User-Agent标头(http://developer.github.com/v3/#user-agent-required)。查看https://developer.github.com以了解其他可能的原因。 –
添加了用户代理,'CURLOPT_USERAGENT' – Federkun
感谢它的工作。 –