douwen1901 2016-06-23 12:53
浏览 55
已采纳

如何使用php发送curl请求[关闭]

How do i send following curl request with php

$ curl -X POST -u "client_id:secret" https://bitbucket.org/site/oauth2/access_token 
-d grant_type=authorization_code -d code={code}
  • 写回答

3条回答 默认 最新

  • douhuan3420 2016-06-23 13:27
    关注

    Use GuzzleHttp.

    <?php
    $client = new GuzzleHttp\Client();
    $response = $client->request('POST', 'https://bitbucket.org/site/oauth2/access_token', [
        'auth' => ['client_id', 'secret'],
        'form_params' => [
            'grant_type' => 'authorization_code',
            'code' => 'code'
        ]
    ]);
    $code = $response->getStatusCode(); // must be 200
    $reason = $response->getReasonPhrase(); // must be OK
    $body = (string) $response->getBody(); // must have your data
    

    Attention, if you are implementing an OAuth Client, I strongly recommend using an opensource library:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到