2014-10-07 56 views
0

所以我試圖通過http post方法來製作這個小API。但我在這裏遇到小問題。 我有這個代碼,我用來做一個http調用domain.com/smsapp/service ....,但是,我得到的答覆是這樣的: - boolean false 這裏可能有什麼問題?我不知道這裏會出現什麼問題。簡單的http調用通過cURL返回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("[email protected]", "got", "message"); 
} 

我都沒有得到任何消息,也沒有任何錯誤。我只得到布爾錯誤。 對此的任何建議表示讚賞。

+2

捲曲返回出錯假。檢查'curl_error($ ch)'以獲取有關錯誤的詳細信息。 – 2014-10-07 19:16:33

+0

@MarcB 調查返回這個'不能解析主機:(無);主機未找到。但我很確定我的網址是有效的。 – user2619381 2014-10-07 19:21:07

+2

您的網址編碼了整個網址。將'http://'變成'http%3A%2F%2F',現在它不再是一個網址了。 – 2014-10-07 19:22:31

回答

0

嘗試改變這一點: 在功能SendSMS: -

$u="www.domain.com/smsapp/$service?id=$id" . "&message=" . $message . "&number=$number" . "&ip=" . $userip; 

,這在功能sendPost: -

curl_setopt($ch, CURLOPT_URL, "http://" . urlencode($Url)); 
+0

我仍然得到相同的錯誤。 – user2619381 2014-10-07 19:46:24