我使用php-ccurl发送http请求进行消息发送,但它会给Object moved to here带来错误。
<?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);
?>
您试图访问的URL不存在或已被移动。
<?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);
要跟踪位置,请添加此行:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
如果你想在后字段中使用空格或"@"等特殊字符,你需要对其进行url编码:
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".urlencode('XXXXX')."&password=".urlencode('XXXXXXX')."&to=".urlencode('XXXXXXXXXX')."&from=".urlencode('XXXXXX')."&message=".urlencode('Get Testing....'));
请先检查您的URL,如果正确,请尝试以下操作:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // changed from 0 to 1
php-ssl-ccurl可能重复:对象移动错误