很抱歉打扰你们,但我是PHP的初学者,想要向API发送请求,并希望通过API密钥接收JSON。
我做错了什么?
<?php
$url = 'https://10.1.0.5:9443/oauth/token';
$clientsecret = 'password';
$clientid = 'admin';
$myvars = 'client_id=' . $clientid . '&client_secret=' . $clientsecret . '&grant_type=' . 'client_credentials';
echo $myvars;
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
echo $response;
curl_close($ch);
?>
希望这已经足够了!