我已经在多块板上阅读了所有内容,但没有成功……需要大脑的信任。
我会得到什么:
HTTP / 1.1 400错误请求
preload {“错误”:“ unsupported_grant_type”}
我的目标:从FQDN / api / token端点检索OAuth令牌
我有:端点,用户名和密码(没有秘密或密钥)
我可以从外壳中卷曲并获得令牌-我只是无法获得php来完成它> /
我的代码不再属于我了,因为我非常确定我是问题所在,但这是我目前正在尝试利用的内容:(有人可以指出我在哪里成为木偶!)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://FQDN/api/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"grant_type\":\"password\",\"username\": \"user@domain.com.au\",\"password\": \"userPasswd\"}",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Content-Length: 96",
"Accept: application/json"
),
CURLOPT_HEADER => true,
CURLOPT_POST => true,
CURLOPT_HTTPAUTH => basic
));
$response = curl_exec($curl);
print_r(curl_getinfo($curl));
print_r($response);
curl_close($curl);
答案 0 :(得分:1)
根据注释,您需要发送键值对:
$data = array(
"grant_type" => "password",
"username" => "username",
"password" => "password"
)
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));