【发布时间】:2016-09-27 00:57:02
【问题描述】:
你好,很棒的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 -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>';
?>
谢谢
【问题讨论】:
标签: javascript php json curl