I am trying to call API parameters dynamically. Below is the code
<?php
$apikey="<API_KEY>";
$senderid="TESTIN";
$channel=2;
$dcs=0;
$flashsms=0;
$number="9171276664,678785612";
$text="Hello Testing message dynamically";
$route="11";
$ch=curl_init("https://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=".$apikey.'&senderid='.$senderid.'&channel='.$channel.'&DCS='.$dcs.'&flashsms='.$flashsms.'&number='.$number.'&text='.$text.'&route='.$route);
?>
It is throwing bad http request error!!!
You need to urlencode every char, you can also use http build query to make it more readable : then can you send the errors you have if you still have one ?
<?php
$params = Array(
'apikey' => "xx",
'senderid' => "TESTIN",
'channel' => 2,
'dcs' => 0,
'flashsms' => 0,
'number' => "1234,4567",
'text' => "Hello Testing message dynamically",
'route' => "11"
) ;
$url = 'https://www.smsgatewayhub.com/api/mt/SendSMS?'.http_build_query($params) ;
$ch=curl_init($url) ;
?>
Not all symbols is allowed in the url (eg: ';', '/', '?', ':', '@', '=', '&' and space), so you should use the urlencode function for your parameters.
<?php
...
$number=urlencode("xxxxxxxxxxxx,xxxxxxxxxxxx");
$text=urlencode("Hello Testing message dynamically");
...
$ch=curl_init("https://www.smsgatewayhub.com/api/mt/SendSMS?APIKey=".$apikey.'&senderid='.$senderid.'&channel='.$channel.'&DCS='.$dcs.'&flashsms='.$flashsms.'&number='.$number.'&text='.$text.'&route='.$route);
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.