Sample code for how to send SMS in java using HTTP Requests
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
public class SendSMS {
public static void main(String[] args) {
try {
String requestUrl = "http://sms.cellapps.com/sendsms.php?"+
"UserId=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Pwd=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Mobileno=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Msg=" + URLEncoder.encode("This is test sms", "UTF-8") +
"&SenderId=" + URLEncoder.encode("Alert", "UTF-8");
System.out.println("URL : "+requestUrl);
URL url = new URL(requestUrl);
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
System.out.println("Request Status code : " +uc.getResponseCode());
if(uc.getResponseCode()== 200){
System.out.println("Message Send Successfully");
}
uc.disconnect();
} catch(Exception ex) {
System.out.println("Error :while sending Message");
System.out.println(ex);
}
}
}
import java.net.URL;
import java.net.URLEncoder;
public class SendSMS {
public static void main(String[] args) {
try {
String requestUrl = "http://sms.cellapps.com/sendsms.php?"+
"UserId=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Pwd=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Mobileno=" + URLEncoder.encode("XXXX", "UTF-8") +
"&Msg=" + URLEncoder.encode("This is test sms", "UTF-8") +
"&SenderId=" + URLEncoder.encode("Alert", "UTF-8");
System.out.println("URL : "+requestUrl);
URL url = new URL(requestUrl);
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
System.out.println("Request Status code : " +uc.getResponseCode());
if(uc.getResponseCode()== 200){
System.out.println("Message Send Successfully");
}
uc.disconnect();
} catch(Exception ex) {
System.out.println("Error :while sending Message");
System.out.println(ex);
}
}
}
It is very easy, you have to sign up an account at MsgClub and go to developer tool for Javascript. We will provide you simple steps to integrate Bulk SMS API Java into your website/application/software.
ReplyDelete