Note : If you submit large number of request, always use XML API for better performance.
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=message&sender=senderid&route=1
What is Url Encoding?
URL encoding converts characters into a format that can be send through internet We should use urlencode for all GET parameters because POST parameters are automatically encoded.
Why Url Encoding?
URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.URLs use some characters for special use in defining their syntax,when these characters are not used in their special role inside a URL, they need to be encoded.Url encoding is done to encode user input
Example:
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999&message=test & new&mobile&sender=123456&route=default
In this api the message content "test & new" includes '&' operator,due to which url encoding is necessary, otherwise it will break your message content and an incomplete message will be sent
Encoded Api
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999&message=test+%26+new&mobile&sender=123456&route=default
By encoding message content in api,complete message will be sent
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=test+%26+new&sender=123456
To send message on multiple numbers numbers should be comma separated
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=test+%26+new&sender=123456&unicode=1
To send Unicode message one more parameter will be added i.e unicode and it's value will be set to 1
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=test+%26+new&sender=123456&flash=1
To send Flash message one more parameter will be added i.e flash and it's value will be set to 1
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=test+%26+new&sender=123456&response=json
To get response in json format one more parameter will be added i.e response and it's value will be set to json
http://sms.asaptech.net/api/sendhttp.php?authkey=YourAuthKey&mobiles=9999999999,919999999999&message=test+%26+new&sender=123456&schtime=2014-09-30 19:23:40
To schedule message i.e for future , one parameter will be added i.e schtime and it's value should be equal to that date and time,at which message should be sent. Note: for Scheduling, date and time are mandatory.
<?php
//Your authentication key $authKey
= "YourAuthKey"; //Multiple
mobiles numbers separated by comma $mobileNumber
= "9999999"; //Sender
ID,While using route4 sender id should be 6 characters long.
$senderId = "102234"; //Your
message to send, Add URL encoding here. $message
= urlencode("Test message");
//Define route
$route = "default"; //Prepare
you post parameters $postData
= array( 'authkey'
=> $authKey,
'mobiles' => $mobileNumber, 'message'
=> $message,
'sender' => $senderId, 'route'
=> $route ); //API
URL $url="http://sms.asaptech.net/sendhttp.php";
// init the resource
$ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_URL
=> $url, CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS
=> $postData
//,CURLOPT_FOLLOWLOCATION => true
)); //Ignore
SSL certificate verification curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); //get
response $output
= curl_exec($ch);
//Print error if any
if(curl_errno($ch))
{ echo
'error:' .
curl_error($ch);
} curl_close($ch);
echo $output; ?>
import urllib # Python URL functions
import urllib2 # Python URL functions authkey
= "YourAuthKey" # Your authentication key. mobiles
= "9999999999" # Multiple mobiles numbers separated by comma.
message = "Test
message" # Your message to send.
sender = "112233"
# Sender ID,While using route4 sender
id should be 6 characters long. route =
"default"
# Define route # Prepare you post
parameters values =
{ 'authkey'
: authkey,
'mobiles' : mobiles,
'message' :
message, 'sender'
: sender,
'route' :
route } url =
"http://sms.asaptech.net/sendhttp.php" # API URL postdata =
urllib.urlencode(values) # URL
encoding the data here. req =
urllib2.Request(url, postdata)
response = urllib2.urlopen(req)
output = response.read() # Get Response
print output # Print Response
//Your authentication key
String authkey = "YourAuthKey";
//Multiple mobiles numbers separated by comma
String mobiles = "9999999";
//Sender ID,While using route4 sender id should be 6 characters long.
String senderId = "102234";
//Your message to send, Add URL encoding here.
String message = "Test message";
//define route
String route="default";
//Prepare Url
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;
//encoding message
String encoded_message=URLEncoder.encode(message);
//Send SMS API
String mainUrl="http://sms.asaptech.net/sendhttp.php?";
//Prepare parameter string
StringBuilder sbPostData= new StringBuilder(mainUrl);
sbPostData.append("authkey="+authkey);
sbPostData.append("&mobiles="+mobiles);
sbPostData.append("&message="+encoded_message);
sbPostData.append("&route="+route);
sbPostData.append("&sender="+senderId);
//final string
mainUrl = sbPostData.toString();
try
{
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response
System.out.println(response);
//finally close connection
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
import java.io.*; import
java.net.URL; import
java.net.HttpURLConnection; class
Functions {
public static
String hitUrl(String
urlToHit, String param)
{ try
{ URL url =
new URL(urlToHit); HttpURLConnection http
= (HttpURLConnection)url.openConnection(); http.setDoOutput(true);
http.setDoInput(true);
http.setRequestMethod("POST");
DataOutputStream wr =
new DataOutputStream(http.getOutputStream());
wr.writeBytes(param); wr.flush();
wr.close(); http.disconnect();
BufferedReader in =
new BufferedReader(new InputStreamReader(http.getInputStream())); String inputLine;
if ((inputLine =
in.readLine()) !=
null) {
in.close(); return
inputLine; }
else {
in.close(); return
"-1"; } }
catch(Exception
e) {
System.out.println("Exception Caught..!!!"); e.printStackTrace();
return "-2"; }
} }
public class
HitXmlData {
public static
void main(String[] args) {
String strUrl = "http://sms.asaptech.net/api/postsms.php"; String xmlData =
"data= <MESSAGE>
<AUTHKEY>YOURAUTHKEY</AUTHKEY> <ROUTE>default</ROUTE> <SMS
TEXT='message1 testing'
FROM='AAAAAA'>
<ADDRESS TO='9999999990'></ADDRESS> </SMS> </MESSAGE>" String output
= Functions.hitUrl(strUrl,
xmlData);
System.out.println("Output is: "+output);
} }
//Your authentication key string authKey =
"YourAuthKey"; //Multiple mobiles numbers separated by
comma string mobileNumber =
"9999999"; //Sender ID,While using route4 sender id should be 6 characters
long. string senderId =
"102234"; //Your message to send, Add URL encoding here.
string message = HttpUtility.UrlEncode("Test message"); //Prepare
you post parameters StringBuilder sbPostData =
new StringBuilder(); sbPostData.AppendFormat("authkey={0}", authKey); sbPostData.AppendFormat("&mobiles={0}",
mobileNumber);
sbPostData.AppendFormat("&message={0}", message); sbPostData.AppendFormat("&sender={0}",
senderId);
sbPostData.AppendFormat("&route={0}", "default");
try {
//Call Send SMS API string sendSMSUri =
"http://sms.asaptech.net/sendhttp.php";
//Create HTTPWebrequest HttpWebRequest
httpWReq = (HttpWebRequest)WebRequest.Create(sendSMSUri);
//Prepare and Add URL Encoded data
UTF8Encoding encoding = new
UTF8Encoding(); byte[] data =
encoding.GetBytes(sbPostData.ToString());
//Specify post method httpWReq.Method =
"POST";
httpWReq.ContentType
= "application/x-www-form-urlencoded"; httpWReq.ContentLength
= data.Length; using (Stream
stream = httpWReq.GetRequestStream())
{ stream.Write(data, 0,
data.Length); }
//Get the response HttpWebResponse
response = (HttpWebResponse)httpWReq.GetResponse();
StreamReader reader = new
StreamReader(response.GetResponseStream());
string responseString = reader.ReadToEnd();
//Close the response reader.Close();
response.Close(); }
catch (SystemException
ex) {
MessageBox.Show(ex.Message.ToString());
}
try
{
string strResult = "";
//Prepare you post parameters
var postValues = new List<KeyValuePair<string, string>>();
//Your authentication key
postValues.Add(new KeyValuePair<string, string>("authkey", "YourAuthKey"));
//Multiple mobiles numbers separated by comma
postValues.Add(new KeyValuePair<string, string>("mobiles", "9999999"));
//Sender ID,While using route4 sender id should be 6 characters long.
postValues.Add(new KeyValuePair<string, string>("sender", "102234"));
//Your message to send, Add URL encoding here.
string message = HttpUtility.UrlEncode("Test message");
postValues.Add(new KeyValuePair<string, string>("message", message));
//Select route
postValues.Add(new KeyValuePair<string, string>("route","default"));
//Prepare API to send SMS
Uri requesturl = new Uri("http://sms.asaptech.net/sendhttp.php");
//create httpclient request
var httpClient = new HttpClient();
var httpContent = new HttpRequestMessage(HttpMethod.Post, requesturl);
httpContent.Headers.ExpectContinue = false;
httpContent.Content = new FormUrlEncodedContent(postValues);
HttpResponseMessage response = await httpClient.SendAsync(httpContent);
//Get response
var result = await response.Content.ReadAsStringAsync();
strResult = result.ToString();
response.Dispose();
httpClient.Dispose();
httpContent.Dispose();
}
catch (Exception ex)
{
throw ex;
}
//Your authentication key
String authkey = "YourAuthKey";
//Multiple mobiles numbers separated by comma
String mobiles = "9999999";
//Sender ID,While using route4 sender id should be 6 characters long.
String senderId = "102234";
//Your message to send, Add URL encoding here.
String message = "Test message";
//define route
String route="default";
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;
//encoding message
String encoded_message=URLEncoder.encode(message);
//Send SMS API
String mainUrl="http://sms.asaptech.net/sendhttp.php?";
//Prepare parameter string
StringBuilder sbPostData= new StringBuilder(mainUrl);
sbPostData.append("authkey="+authkey);
sbPostData.append("&mobiles="+mobiles);
sbPostData.append("&message="+encoded_message);
sbPostData.append("&route="+route);
sbPostData.append("&sender="+senderId);
//final string
mainUrl = sbPostData.toString();
try
{
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response
String response;
while ((response = reader.readLine()) != null)
//print response
Log.d("RESPONSE", ""+response);
//finally close connection
reader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//Create Objects
NSMutableData * responseData;
NSURLConnection * connection;
// In your viewDidLoad method add this lines
-(void)viewDidLoad
{
[super viewDidLoad];
//Your authentication key
NSString * authkey = @"YourAuthKey";
//Multiple mobiles numbers separated by comma
NSString * mobiles = @"9999999";
//Sender ID,While using route4 sender id should be 6 characters long.
NSString * senderId = @"102234";
//Your message to send, Add URL encoding here.
NSString * message = @"Test message";
//define route
NSString * route = @"default";
// Prepare your url to send sms with this parameters.
NSString * url = [[NSString stringWithFormat:@"http://sms.asaptech.net/sendhttp.php?authkey=%@&mobiles=%@&message=%@&sender=%@&route=%@", authkey, mobiles, message, senderId, route] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
// implement URLConnection Delegate Methods as follow
-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//Get response data
responseData = [NSMutableData data];
}
-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[responseData appendData:data];
}
-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
}
-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
// Get response data in NSString.
NSString * responceStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
}