我通过硬编码访问令牌从Web服务获取数据,但是当我尝试使用curl获取访问代码时,它不会
这是api给出的代码
curl -k -d "grant_type=password&username=Username&password=Password" \
-H "Authorization: Basic SUpfTjFmTlo1UmZLS0VrYVBFVUtOUXJZcHFjYTpiRU1NNE9ITmxJYUlSXzNaUTA4akhSMnV0UkVh" \
https://api.lankagate.gov.lk:8243/token
这是我的代码
function get_exam_mode_of_study() {
$URL = "test_url";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Basic SUpfTjFmTlo1UmZLS0VrYVBFVUtOUXJZcHFjYTpiRU1NNE9ITmxJYUlSXzNaUTA4akhSMnV0UkVh',
'Content-Type: application/x-www-form-urlencoded'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
// curl_setopt($ch, CURLOPT_HTTPHEADER, array());
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'grant_type: password',
'username: pass',
'password: user'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print_r($output);
exit;
curl_close($ch);
// }
}
我该怎么做