dragon188199 2017-10-30 08:49
浏览 92

使用cURL连接到OpenId会产生错误

I am using the following code to access an OpenId system and request a bearer token.

if (isset($_GET['code'])) {
    // try to get an access token
    $code = $_GET['code'];
    $url = 'https://3rdpartydomain.com/connect/token';
    $params = array(
        "code" => $code,
        "client_id" => CLIENTID,
        "client_secret" => CLIENTSECRET,
        "redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
        "grant_type" => "authorization_code"
    );

    $ch = curl_init();
    curl_setopt($ch, constant("CURLOPT_" . 'URL'), $url);
    curl_setopt($ch, constant("CURLOPT_" . 'POST'), true);
    curl_setopt($ch, constant("CURLOPT_" . 'POSTFIELDS'), $params);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    if ($info['http_code'] === 200) {
        header('Content-Type: ' . $info['content_type']);
        return $output;
    } else {
        return 'An error happened';
    }
} else {

    $url = "https://3rdpartydomain.com/connect/token";

    $params = array(
        "response_type" => "code",
        "client_id" => CLIENTID,
        "redirect_uri" => 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"],
        "scope" => "openid"
    );

    $request_to = $url . '?' . http_build_query($params);

    header("Location: " . $request_to);
}

However, I'm getting the following message:

{"Message":"The requested resource does not support http method 'GET'."}

Can someone help identify the correct to my code please?

Thanks!

  • 写回答

2条回答 默认 最新

  • duanpie2414 2017-10-30 09:00
    关注

    Add these:

    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

    评论

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题