Send SMS with JAVAScript


ASP SMS messaging is one of the services we offer. Here we'll show you how to use our SMS gateway in ASP. Take the SMS ASP script code below to send SMS via Developers' Central. Simply register for an account, and you will automatically receive 10 FREE SMS credits to try our service.

Code to send SMS in JAVAScript:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.*;
public class sendsmsApi
{
public static String retval = "";
public static String SMSSender(String APIKey, String number, String text, String senderid,String channel ,String flashsms,String route)
{
String rsp = "";
try {
// Construct The Post Data
String data = URLEncoder.encode("APIKey", "UTF-8") + "=" + URLEncoder.encode(APIKey, "UTF-8");
data += "&" + URLEncoder.encode("senderid", "UTF-8") + "=" + URLEncoder.encode(senderid, "UTF-8");
data += "&" + URLEncoder.encode("channel", "UTF-8") + "=" + URLEncoder.encode(channel, "UTF-8");
data += "&" + URLEncoder.encode("DCS", "UTF-8") + "=" + URLEncoder.encode("0", "UTF-8");
data += "&" + URLEncoder.encode("flashsms", "UTF-8") + "=" + URLEncoder.encode(flashsms, "UTF-8");
data += "&" + URLEncoder.encode("number", "UTF-8") + "=" + URLEncoder.encode(number, "UTF-8");
data += "&" + URLEncoder.encode("text", "UTF-8") + "=" + URLEncoder.encode(text, "UTF-8");
data += "&" + URLEncoder.encode("route", "UTF-8") + "=" + URLEncoder.encode(route, "UTF-8");
String url1="http://smppsmshub.in/api/mt/SendSMS";
url1+="?"+data;
URL url=new URL(url1);
URLConnection connection = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null)
{
sb = sb.append(line);
}
rsp = sb.toString();
}
catch (Exception e)
{
e.printStackTrace();
}
return rsp;
}
public static void main(String[] args) {

String response = SMSSender("Enter your API key", "Enter your number", "Enter test message", "Enter SenderID"," Enter Channel" ,"Flash", "Route");
System.out.println("Response"+response);
}
}
Type the above number: