2015-09-04 20 views
0

我想从短信主机服务器收到错误 curl_error curl_errno curl_strerror所有这些函数返回错误,但不是以我想要的方式,mysmshost说,你会收到代码,如错误的手机号码202 ,301错误的身份验证,我想接收那些错误代码,请帮助。 这是我的代码。我想收回错误代码。通过短信主机服务器在PHP

//sending message 
     $authKey = "my_authentication_key"; 
     $senderId = "sender"; 
     $message = urlencode("Hello Its Working.."); 
     $route = "1"; 
     $campaign = 'Default'; 
    //Prepare you post parameters 
$postData = array(
    'authkey' => $authKey, 
    'mobiles' => $number, 
    'message' => $message, 
    'sender' => $senderId, 
    'route' => $route, 
    'campaign' => $campaign 
); 
//API URL 
$url="http://sms.mysmshost.com/sendhttp.php"; 
// init the resource 
$ch = curl_init(); 
curl_setopt_array($ch, array(
    CURLOPT_URL => $url, 
    CURLOPT_RETURNTRANSFER => true, 
    CURLOPT_POST => true, 
    CURLOPT_POSTFIELDS => $postData 
    //,CURLOPT_FOLLOWLOCATION => true 
)); 
//Ignore SSL certificate verification 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
//get response 
$output = curl_exec($ch); 
//Print error if any 
if(curl_errno($ch)) 
{ 
    echo curl_error($ch)."-curl_error<br/>"; 
    $chcode =curl_errno($ch); 
    echo $chcode; 
    echo '<br/>error:' . curl_strerror($chcode)."<br/>"; 
} 
curl_close($ch); 
echo $output; 

Curl_errorno()没有执行,即使我打印他们没有条件他们没有结果。

+0

什么是你从curl_error –

+0

Curl_errorno获得()不执行错误,即使我打印出来,如果没有条件,他们给没有结果。 –

+0

你检查下面的代码 –

回答

0

试试这个

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_ENCODING, ''); 
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); 

$server_output = curl_exec($ch); 
curl_close($ch); 

print_r($server_output);