/*Send SMS using JAVA*/

//Your APIKEY key
String apikey = "YourApikey";
//Approved sender id(6 characters string only).
String senderId = "TESTIN";
//Message channel Promotional=1 or Transactional=2.
String channel = "2";
//Default is 0 for normal message, Set 8 for unicode sms.
String DCS = 0;
 //Default is 0 for normal sms, Set 1 for immediate display.
 String flashsms = 0;
//Your message to send.
String message = "Test message";
//Recipient mobile number (pass with comma seprated if need to send on more then one number)
String number = "9999999";
//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="https://www.smsgatewayhub.com/api/mt/SendSMS?";

//Prepare parameter string 
StringBuilder sbPostData= new StringBuilder(url);
sbPostData.append("apikey="+apikey); 
sbPostData.append("&senderId="+senderId);
sbPostData.append("&channel="+channel);
sbPostData.append("&DCS="+DCS);
sbPostData.append("&flashsms="+flashsms);
sbPostData.append("&message="+message);
sbPostData.append("&number="+number);
sbPostData.append("&route="+route);

//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();
}