-5
What is the correct form of this code in Curl php?
curl --user {client_id}:{client_secret} -H 'Content-Type: application/x-www-form-urlencoded' -d grant_type=client_credentials https://sitealvo.com.br
-5
What is the correct form of this code in Curl php?
curl --user {client_id}:{client_secret} -H 'Content-Type: application/x-www-form-urlencoded' -d grant_type=client_credentials https://sitealvo.com.br
1
Let’s go in pieces:
// O site alvo:
$ch = curl_init('https://sitealvo.com.br');
// O usuário e senha (o formato é usuario:senha):
curl_setopt($ch, CURLOPT_USERPWD, '{client_id}:{client_secret}');
// O cabeçalho:
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
// O corpo (lembrando que ele é um application/x-www-form-urlencoded):
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_POST, 1);
// Faz o curl retornar para váriavel:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Aqui tem o resultado:
$result = curl_exec($ch);
// Ou o erro:
$erro = curl_error($ch);
Browser other questions tagged php curl
You are not signed in. Login or sign up in order to post.