在PS中,我做到了:
$body=@{
'code'='$code'
'access_token'=$token
}
$result = Invoke-RestMethod -Uri $uri -Method Post -Body $body
完美。如何在PHP Curl中做同样的事情?
我已经尝试过这样的事情:
$data = array("code" => $code, "access_token" => $token);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POST, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"code=" . $code,
"access_token=" . $token
));
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('ContentType:text/plain'));
$result=curl_exec ($ch);
print_r($result);
但是我不断收到错误消息,例如:参数令牌丢失。