所以我尝试通过http-post方法制作这个小型API。但我在这里遇到了一些小问题。我有这样的代码,我正在使用它对domain.com/smssapp/service…进行http调用。,但是,我得到的响应是:-boolean false这里可能出了什么问题?我不知道这里会出什么问题。
function sendSMS($message,$number)
{
$id = "Dogbag";
$service = "sms_api_call_receiver.php";
$userip = $_SERVER['REMOTE_ADDR'];
/*** Build the request parameters ***/
$request="Send-Sms";
$u="http://www.domain.com/smsapp/$service?id=$id" . "&message=" . $message . "&number=$number" . "&ip=" . $userip;
$result = sendPost($u, $request);
var_dump($u);
return $result;
}//function
function sendPost($Url, $strRequest)
{
// Initialisation
$ch=curl_init();
// Set parameters
curl_setopt($ch, CURLOPT_URL, urlencode($Url));
// Return a variable instead of posting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Active the POST method
curl_setopt($ch, CURLOPT_POST, 1) ;
// Request
curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
// execute the connexion
$result = curl_exec($ch);
// Close it
curl_close($ch);
return $result;
}
sms_api_call_receiver.php
if(isset($_GET['message']))
{
mail("myemail@gmail.com", "got", "message");
}
我既没有收到任何消息,也没有收到任何错误。我只得到布尔值false。如有任何建议,我们将不胜感激。
尝试更改:在函数SendSMS中:-
$u="www.domain.com/smsapp/$service?id=$id" . "&message=" . $message . "&number=$number" . "&ip=" . $userip;
这在函数sendPost中:-
curl_setopt($ch, CURLOPT_URL, "http://" . urlencode($Url));