【问题标题】:php curl to send http request for sms sending : object moved errorphp curl发送http请求以发送短信:对象移动错误
【发布时间】:2015-03-18 13:26:37
【问题描述】:

我正在使用 php curl 发送 http 请求以进行消息发送,但它使对象移到此处错误。

<?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);

?>

【问题讨论】:

  • 您使用的网址是否正确?

标签: php curl


【解决方案1】:

您尝试访问的 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);

【讨论】:

    【解决方案2】:

    要跟踪位置,请添加以下行:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    

    如果您打算在 postfield 中使用空格或“@”等特殊字符,则需要对其进行 urlencode:

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

    【讨论】:

      【解决方案3】:

      请先检查你的网址,如果正确,试试这个:

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

      php ssl curl : object moved error 可能重复

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-07-17
        • 1970-01-01
        • 1970-01-01
        • 2017-04-23
        • 1970-01-01
        • 1970-01-01
        • 2014-11-06
        相关资源
        最近更新 更多