php - 如何通过 cURL 正确地将 POST 请求发送到 REST API?
问题描述
我正在尝试通过交换从 URL 接收到的代码来获取访问令牌,并且我已经配置了重定向 uri 和其他配置。以下是我的callback.php:
$code = $_GET["code"];
$client_id = "";//actual client id
$client_secret = ""//actual client secret;
$redirect_uri = "http%3A%2F%2Flocalhost%2Ftest%2Fwebex_integration_test%2Fcallback.php";
$postRequest = array(
"client_id" => ""//actual client id,
"client_secret" => ""//actual client secret,
"code" => $_GET["code"],
"redirect_uri" => "http%3A%2F%2Flocalhost%2Ftest%2Fwebex_integration_test%2Fcallback.php",
"code_verifier" => "abc"
);
$cURLConnection = curl_init("https://api.webex.com/v1/oauth2/token?grant_type=authorization_code&client_id=$client_id&client_secret=$client_secret&code=$code&redirect_uri=$redirect_uri&code_verifier=abc");
curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Connection: Keep-Alive'
));
$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);
$jsonArrayResponse = json_decode($apiResponse);
print_r($jsonArrayResponse);
上述请求导致空白页。我期待访问令牌。
解决方案
试试这个类的 PHP 作曲家,不要浪费时间
推荐阅读
- c# - 将表名作为参数传递给 SqlCommand 的问题
- textarea - 如何捕获在文本区域控件中输入并以角度存储到数据库中的文本和图像 url
- java - 如何为具有多个类和文件夹的摇摆应用程序创建 jar 文件?
- javascript - 在 chrome 应用程序选项卡中使用 axios 请求访问 cookie 的方法
- android - 打开失败:Android(6.0.1)系统应用程序中的EACCES(权限被拒绝)
- excel - 根据多个条件计算不同的值
- node.js - nodejs child_process spawn 和 exec 不会杀死 process.kill(pid) 上的进程
- micronaut - 为什么 Micronaut 发送连接:即使 > 499 也关闭?
- wordpress - Woocommerce 样本堆叠(彼此重叠)
- vba - VBA:波动表,如何更改表 127 第 3 列中的值,取决于表 126 第 3 列?