你好,很棒的 stackoverflow,我正在尝试将下面的 api 从 javascript 重写为 php,以便能够使 json curl ,但在下面显示错误
Warning: curl_setopt() expects exactly 3 parameters, 4 given in C:\xampp\htdocs\firstcare\curl.php on line 15
js curl
curl -X POST
"http://my_api.com/accesstoken?grant_type=client_credentials"
-H "Content-Type: application/x-www-form-urlencoded"
-d 'client_id=$myClient_id'
-d 'client_secret=$myClient_secret
php curl 转换
<?php
// 0 means unlimited timeout
ini_set('max_execution_time', 0);
$data = array(
'Content-Type' => 'application/x-www-form-urlencoded',
'client_id' => 'myclient_id',
'client_secret' => 'myclient_secret'
);
$url='http://my_api.com/accesstoken?grant_type=client_credentials';
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url,$data);
$result=curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
echo '<pre>' . print_r($json, true) . '</pre>';
?>
谢谢
最佳答案
抛出错误,因为 curl_setopt
需要 3 个参数 - 您在此处传递了 4 个参数:
curl_setopt($ch, CURLOPT_URL,$url,$data);
关于javascript - 将 json api curl 从 javascript 重写为 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37504591/