我正在尝试为以下 API 编写 PHP 代码:
curl -u ********* -d email=tester@gmail.com \
--data-urlencode msg="First message from domain API" \
--data-urlencode url="http://www.domain.com/welcome" \
https://api.domain.com/1/send
PHP代码:
<?php
$url = "https://api.domain.com/1/send ";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_USERPWD, "*********");
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "email=test@outlook.com&msg=hi%url=http://yahoo.com/"); // add POST fields
$result = curl_exec($ch);
curl_close($ch);
echo $result;
?>
我在处理上述 API 时做错了什么?