2013-03-12 69 views
-1

我使用Curl使用网关发送短信,一旦一切正常就获得200,如果现在不发送,则获得400,我应该从网关获得其他信息,例如电话号码和其他信息,所以我错过了什么?在PHP中的卷曲响应

// if the Form is submited 
//if (isset($_POST['PhoneNumber'])) { 
if ($_SERVER['REQUEST_METHOD'] == "POST"){ 

// Fetch Phone Number and escape it for security 
$Phone = mysql_real_escape_string($_POST['PhoneNumber']); 

// Fetch Text and escape it for security 
$Text = mysql_real_escape_string($_POST['Text']); 

// Structure the URl 
$url = "http://xxxxxxxxxxx:xxxx?PhoneNumber=".urlencode($Phone)."&Text=".urlencode($Text)."&User=xxx&Password=xxx"; 

// Handeling the Curl 
$handle = curl_init($url); 

curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); 

/* Get the HTML or whatever is linked in $url. */ 
$response = curl_exec($handle); 

/* Check for 404 (file not found). */ 
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); 

if ($httpCode=="200"){ 

    // if everything is okey , the gateway returns 200 which means OK 
    echo "Massage Was Sent , Thank you "; 



} elseif ($httpCode=="400"){ 
    // if there was an error , the form returns a 400 which means that the sms Failed 
    echo "Massage was not sent , Please Try Again"; 

} 

// Cloase the Curl Connection 
curl_close($handle); 

谢谢您最好的问候,

+0

我不熟悉的卷曲度可言,但'curl_getinfo'是你确定你不想要'$ response'变量?你正在指定'$ handle'。因为我认为你会希望获得有关回复的信息。可能是错误的。 – sircapsalot 2013-03-12 14:14:30

+0

我不明白,我该怎么办? – test 2013-03-12 14:33:44

+0

感谢您的按摩:)(抱歉) – kjetilh 2013-03-12 15:03:44

回答

0

$响应应当包含响应,请尝试: echo '<pre>'; print_r($response); echo '</pre>'; 以显示其内容