你好我試圖讓一個公司的工作REST API,但他們正在使用POST和GET請求,我從來沒有見過。我整天在讀書,並且瞭解一些事情。我可能需要使用cUrl或html表單,但是猜測cUrl更容易。 我怎樣才能通過php在cUrl這個職位請求?第一次與PHP使用cUrl
curl -v https://testgw.gopay.cz/api/oauth2/token \
-X "POST" \
-H "Accept: application/json" \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "<Client ID>:<Client Secret>" \
-d "grant_type=client_credentials&scope=payment-create"
我試着這個,但它不會正確地發送數據。
$client_id = "000000:111111";
function httpPost($url)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
"$client_id",
"grant_type=client_credentials&scope=payment-create"
));
$output=curl_exec($ch);
curl_close($ch);
return $output;
}
echo httpPost("https://testgw.gopay.cz/api/oauth2/token");
'$ client_id'超出範圍。 – Daan