你可以像下面: -
<?php
$data_string = '{"email":"MY_EMAIL","password":"MY_PASSWORD"}';
$ch = curl_init('https://api.voluum.com/auth/session');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Accept: application/json'
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
exit;
}
curl_close ($ch);
var_dump($result);
我運行它,並低於響應發現(因爲我沒有郵件的ID和密碼): - https://prnt.sc/gdz82r
但令人愉快的部分是代碼成功執行當你將提供正確的憑證,那麼它會給你正確的輸出。
你連做任何研究嗎? http://php.net/manual/en/book.curl.php –
@SebastianTkaczyk是的,但我不明白怎麼做:/ –