1

Right now i am facing a problem in executing api for sms gateway. They asked me to hit a url and which is http://bulksmsgateway.in/sendmessage.php?user=........&password=.......&mobile=........&message=.......&sender=.......&type=3

but i have to do it without loading this url in a browser. so i used curl method. and where i get a 400 bad request error.It's a windows server with PHP support.

my code is here below -

$ch = curl_init();

curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_URL, $url);

$contents = curl_exec($ch);

$ee = curl_getinfo($ch);

print_r($ee);

curl_close($ch);

if ($contents){ echo 'sent'; print_r($contents); }else{ echo 'lost'; }

the $ee returns

Array ( [url] => http://bulksmsgateway.in/sendmessage.php?user=usrname&password=pwd&mobile=9126050xxx&message=Thanking you for ordering through FCI.Your Order will be delivered on time.Your order no is 000198.Please keep it for future reference.&sender=SUBANK&type=3

[content_type] => text/html; charset=iso-8859-1
[http_code] => 400
[header_size] => 145
[request_size] => 411
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.094
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.047
[size_upload] => 0
[size_download] => 299
[speed_download] => 3180
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.094
[redirect_time] => 0
[certinfo] => Array
    (
    )

[redirect_url] => 

)

I think the problem is in the message portion. the space in message in url getting error.because a message without space sent successfully. a &nbsp also is not working.and waht for fullstop(.).please help me in this regards.

thanks in advance.

1
  • 1
    Your username and password doesn't contain special characters which are reserved in URL. So please convert &,? to their codes like %26 for & Commented Jun 30, 2014 at 8:24

3 Answers 3

2

You should encode the message query parameter in this way:

$message = urlencode("Thanking you for ordering through FCI.Your Order will be delivered on time.Your order no is 000198.Please keep it for future");

Here's a message parameter with right codification to be sent as GET parameter:

Thanking+you+for+ordering+through+FCI.Your+Order+will+be+delivered+on+time.Your+order+no+is+000198.Please+keep+it+for+future

Sign up to request clarification or add additional context in comments.

Comments

0

http://www.technologyworkshops.net/tutorials-f39/curl-using-get-method-with-php-t135.html

function curlWithGetMethod($url, $data)
    {
    $fields_string = '';

    foreach($data as $key=>$value){
    $fields_string[]=$key.'='.urlencode($value).'&'; }
    $urlStringData = $url.'?'.implode('&',$fields_string);

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10); 
   curl_setopt($ch, CURLOPT_USERAGENT , "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_URL, $urlStringData ); 

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

    return $return;
}

$data = array('first_name' => 'myname', 'email' => '[email protected]', 'phone' => '0123456789',  );
echo curlWithGetMethod(''http://www.technologyworkshops.net/', $data);

Comments

0

i have replace the spaces with %20 and it's works fine for me.thanx for your help everybody...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.