-1

I m sending http request using php curl for message sending but it gives Object moved to here error.

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

?>
jvitasek
  • 810
  • 8
  • 16
Ranjana Bhagwat
  • 31
  • 1
  • 1
  • 4

3 Answers3

1

The URL you are trying to access does not exist or has been moved.

<?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);
Nouman Arshad
  • 593
  • 2
  • 7
0

To follow location, add this line:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

And if you intend to have special characters like space or '@' in postfields, you need to urlencode it:

curl_setopt($ch, CURLOPT_POSTFIELDS, "username=".urlencode('XXXXX')."&password=".urlencode('XXXXXXX')."&to=".urlencode('XXXXXXXXXX')."&from=".urlencode('XXXXXX')."&message=".urlencode('Get Testing....'));
n-dru
  • 9,285
  • 2
  • 29
  • 42
0

Please check your URL first, if that is correct, try this:

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

Possible duplicate of php ssl curl : object moved error

Community
  • 1
  • 1
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30