我正在尝试使用 API。这是文档中提供给我的示例:
curl \
-X POST \
-u YOUR_API_KEY: \
-d '{
"email_id": "YOUR_EMAIL_ID",
"recipient": {
"address": "some.one@email.com"
}
}'
https://api.sendwithus.com/api/v1/send
这是我的尝试:
$url = 'https://api.sendwithus.com/api/v1/send';
$user = 'my_api_key';
$params = array(
'email_id' => 'my_email_id',
'recipient' => array(
'address' => 'my_email_address'
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, $user. ':' . '');
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
curl_close ($ch);
当我 var_dump $result 时,我得到一个空字符串。
你看到我做错了吗?