dongsimang4036
dongsimang4036
2016-04-08 17:08

如何使用php-curl(带凭据)从github获取发布信息?

已采纳

I am able fetch github release details using curl but I want to do this using php.

The command I use in curl is the following:

curl -u user.ca:password -X GET https://api.github.com/repos/xyz/abc/releases
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douxuqiao6394 douxuqiao6394 5年前

    The php equivalent of the -u option is CURLOPT_USERPWD.

    curl_setopt($ch, CURLOPT_USERPWD, 'user.ca:password');
    

    In the end you will have something like this:

    $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);    
    
    点赞 评论 复制链接分享

相关推荐