In this Code we can send SMS to any Mobile which are supported by Way2SMS, Just we need to have the Login Credentials of way2sms and then we can send SMS...
// This Code is working Perfectly.....
import java.net.*;
import java.io.*;
class SmsSender
{
//Replace your way2sms username and password below
static final String _userName = "user name";
static final String _password = "password";
static final String _url = "http://ubaid.tk/sms/sms.aspx";
static final String charset = "UTF-8";
//to build the query string that will send a message
private static String buildRequestString(String targetPhoneNo, String message) throws UnsupportedEncodingException
{
String [] params = new String [5];
params[0] = _userName;
params[1] = _password;
params[2] = message;
params[3] = targetPhoneNo;
params[4] = "way2sms";
String query = String.format("uid=%s&pwd=%s&msg=%s&phone=%s&provider=%s",
URLEncoder.encode(params[0],charset),
URLEncoder.encode(params[1],charset),
URLEncoder.encode(params[2],charset),
URLEncoder.encode(params[3],charset),
URLEncoder.encode(params[4],charset)
);
return query;
}
public static void sendMessage(String reciever, String message) throws Exception
{
//To establish the connection and perform the post request
URLConnection connection = new URL(_url + "?" + buildRequestString(reciever,message)).openConnection();
connection.setRequestProperty("Accept-Charset", charset);
//This automatically fires the request and we can use it to determine the response status
InputStream response = connection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(response));
System.out.println(br.readLine());
}
public static void main(String [] args)
throws Exception
{
String testPhoneNo = "Reciever's Number";
String testMessage = "Sending Messages From java is not too hard";
sendMessage(testPhoneNo,testMessage);
}
}
Note : This code doesn't need any xtra API's so you may run if you have the Java JDK kit only.....
eNjoY.............
Note:
to get token use this code
Comments
u r code on way2sms not working fro me!
its showing -1 output.
please help
prasad1790@gmail.com
it prints -1 in console and message is not sent.
can anyone provide any alternative ?
Does it really work?
Your code on way2sms not working for me!
its showing -11 output.
please help
bibhutiojha@gmail.com
Your code on way2sms not working for me!
its showing -11 output.
please help
laxman.k1223@gmail.com
We are getting error -11 . Can you please resolve and provide correct solution.
Thanks
Thank you
Your code on way2sms not working for me!
please help
divekarsm@gmail.com
Your code on way2sms not working for me!
please help
divekarsm@gmail.com
u r code on way2sms not working fro me!
its showing -1 output.
please help
pradyut_s@ymail.com
This Code is not running its showing 503 error in http.
Please help me regarding this.
Thanks
Sailendra
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL: http://ubaid.tk/sms/sms.aspx?uid=9699173129&pwd=B3922K&msg=Sending+Messages+From+java+is+not+too+hard&phone=9769760529&provider=way2sms
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.raman.SmsSender.sendMessage(SmsSender.java:35)
at com.raman.SmsSender.main(SmsSender.java:46)
This code not working
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL: http://ubaid.tk/sms/sms.aspx?uid=9699173129&pwd=B3922K&msg=Sending+Messages+From+java+is+not+too+hard&phone=9769760529&provider=way2sms
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.raman.SmsSender.sendMessage(SmsSender.java:35)
at com.raman.SmsSender.main(SmsSender.java:44)
please help shiladitya.basu1987@gmail.com
SEND FREE SMS INDIA TEXT MESSAGES EARN MONEY Fun2earn
de: 503 for URL: http://ubaid.tk/sms/sms.aspx?uid=9043398725&pwd=2264&msg=Sendin
g+Messages+From+java+is+not+too+hard&phone=9345098599&provider=way2sms
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1170)
at SmsSender.sendMessage(SmsSender.java:35)
at SmsSender.main(SmsSender.java:44)
Exception in thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL: http://ubaid.tk/sms/sms.aspx?uid=8790127009&pwd=mubeena123&msg=Sending+Messages+From+java+is+not+too+hard&phone=9581318199&provider=way2sms
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
at dm.SmsSender.sendMessage(SmsSender.java:43)
at dm.SmsSender.main(SmsSender.java:53)
Your code on way2sms not working for me!
please help my mca project
75% complete plese ........
email: g.satheesh48@gmail.com
any one please
These are some refernces for SMS APi Hope this will help you
FullonSMS API
FullonMS API Source Code
The above code is giving me an error
Exception in thread "main" java.net.UnknownHostException: ubaid.tk
i was busy in other job and was unable to update my blog. but now as all of u having problem in sending sms.
i will give u the hit how to send sms but making complete code may be updated late
first we need to send the url with our credentials
"http://site21.way2sms.com/content/Login1.action?username=&password=&loginBTN=Login"
with this url we get redirection url as
"http://site21.way2sms.com/vem.action;jsessionid=8E76B48271B3A594FB4F73A88653D475.w806?id=8E76B48271B3A594FB4F73A88653D475.w806"
this url will not be same but at the end you will have token so parse this redirected url and get the token value i.e. "8E76B48271B3A594FB4F73A88653D475.w806"
now attach this token to ur msg url and this will be as
"http://site21.way2sms.com/smstoss.action?ssaction=ss&Token=8E76B48271B3A594FB4F73A88653D475.w806&mobile=&message=&msgLen=&button=Send%20SMS"
using above steps manually i have done it but making code will take me some time as im busy in other projects
i was busy in other job and was unable to update my blog. but now as all of u having problem in sending sms.
i will give u the hit how to send sms but making complete code may be updated late
first we need to send the url with our credentials
"http://site21.way2sms.com/content/Login1.action?username=&password=&loginBTN=Login"
(give your username after username= and password after password=)
with this url we get redirection url as
"http://site21.way2sms.com/vem.action;jsessionid=8E76B48271B3A594FB4F73A88653D475.w806?id=8E76B48271B3A594FB4F73A88653D475.w806"
this url will not be same but at the end you will have token so parse this redirected url and get the token value i.e. "8E76B48271B3A594FB4F73A88653D475.w806"
now attach this token to ur msg url and this will be as
"http://site21.way2sms.com/smstoss.action?ssaction=ss&Token=8E76B48271B3A594FB4F73A88653D475.w806&mobile=&message=&msgLen=&button=Send%20SMS"
(give receiver number after mobile=, message after message= and the length of message after msgLen=)
using above steps manually i have done it but making code will take me some time as im busy in other projects
HttpURLConnection con1 = (HttpURLConnection)(new URL( "http://site21.way2sms.com/smstoss.action?ssaction=ss&Token=EE84A7C9930BA66B7E0C78533B26E6A5.w805&mobile=9632292221&message=hi&msgLen=2&button=Send%20SMS" ).openConnection());
con1.connect();
programatically i am not able to send message but when i hite this url in browser then i am able to send.