dongsimang4036 2016-04-08 17:08 采纳率: 100%
浏览 72
已采纳

如何使用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 2016-04-08 17:15
    关注

    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);    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?