我有这个代码
$endpoint_url = 'https://accounts.spotify.com/api/token';
// Creates our data array that we want to post to the endpoint
$data_to_post = [
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $redirect_uri,
'client_id' => $client_id,
'client_secret' => $client_secret,
];
// Sets our options array so we can assign them all at once
$options = [
CURLOPT_URL => $endpoint_url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data_to_post,
];
// Initiates the cURL object
$curl = curl_init();
// Assigns our options
curl_setopt_array($curl, $options);
// Executes the cURL POST
$results = curl_exec($curl);
// Be kind, tidy up!
curl_close($curl);
我需要添加标题Content-Type: application/x-www-form-urlencoded
在POST请求中。
我该怎么做?我是PHP的初学者,无法弄清楚:/