php curl发送短信发送的http请求:对象移动错误

时间:2015-03-18 13:26:37

标签: php curl

我使用php curl发送http请求进行消息发送,但它将Object移到此处错误。

<?php 
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,  "http://sms.chromeindia.com/SendSms.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=XXXXX&password=XXXXXXX&   to=XXXXXXXXXX&from=XXXXXX&message=Get Testing....");
$buffer = curl_exec($ch);
if(empty ($buffer))
{ 
 echo " buffer is empty "; 
}
else // enter code here
{ 
 echo $buffer;
} 
curl_close($ch);

?>

3 个答案:

答案 0 :(得分:1)

您尝试访问的网址不存在或已被移动。

&#13;
&#13;
<?php 
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,  "http://sms.chromeindia.com/SendSms.aspx");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=XXXXX&password=XXXXXXX&to=XXXXXXXXXX&from=XXXXXX&message=Get Testing....");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); # This will auto point to new location
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$buffer = curl_exec($ch);
if(empty ($buffer))
{ 
 echo " buffer is empty "; 
}
else
{ 
 echo $buffer;
} 
curl_close($ch);
&#13;
&#13;
&#13;

答案 1 :(得分:0)

要关注位置,请添加以下行:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

如果您打算拥有像太空这样的特殊字符或者&#39; @&#39;在postfields中,你需要对它进行urlencode:

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".urlencode('XXXXX')."&password=".urlencode('XXXXXXX')."&to=".urlencode('XXXXXXXXXX')."&from=".urlencode('XXXXXX')."&message=".urlencode('Get Testing....'));

答案 2 :(得分:0)

请先检查您的网址,如果错误,请尝试以下网址:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // changed from 0 to 1

php ssl curl : object moved error

可能重复