Sending SMS via Way2SMS using java


                  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

Unknown said…
code really works..its awesome..thanks a lot.
Arun said…
It's not working for me, it shows -1 when i run, and as well i didn't receive msg
Unknown said…
SIR
u r code on way2sms not working fro me!
its showing -1 output.
please help
prasad1790@gmail.com
Anonymous said…
Its also not working for me..

it prints -1 in console and message is not sent.

can anyone provide any alternative ?
R.manoj said…
It's not working..it shows the output as -1...you cheat us
Unknown said…
Can you explain a bit so that new programmers also understands..

Does it really work?
Unknown said…
SIR
Your code on way2sms not working for me!
its showing -11 output.
please help
bibhutiojha@gmail.com
laxman said…
SIR
Your code on way2sms not working for me!
its showing -11 output.
please help
laxman.k1223@gmail.com
Rakesh said…
Hi,

We are getting error -11 . Can you please resolve and provide correct solution.

Thanks
prabhu said…
it is showind -11 how to solve this error

Thank you
Unknown said…
Way2sms, and 160by2 has blocked all IP addresses which are used to send bulk sms. So, even the IP of this server is blocked. so thats why you are not able to send SMS from this url.
Unknown said…
Giving -11 as output, as you said Way2Sms blocking the ip's or something in that case how could we go through this.
Unknown said…
SIR
Your code on way2sms not working for me!
please help
divekarsm@gmail.com
Unknown said…
SIR
Your code on way2sms not working for me!

please help
divekarsm@gmail.com
Pradyut said…
SIR
u r code on way2sms not working fro me!
its showing -1 output.
please help
pradyut_s@ymail.com
Hi,

This Code is not running its showing 503 error in http.

Please help me regarding this.

Thanks
Sailendra
Unknown said…
This comment has been removed by the author.
Unknown said…
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:46)
JAVA Learners said…
Sir, ur code is not working get the error.....
Unknown said…
sir you code is not working...... it's giving this message when running:
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
Unknown said…
Fun2earn free sms sending facility provider. Earn 4 paisa for send per sms. user can send sms on any Indian mobile number. Full sms sending is easy.
SEND FREE SMS INDIA TEXT MESSAGES EARN MONEY Fun2earn
otr214430 said…
This comment has been removed by a blog administrator.
Exception in thread "main" java.io.IOException: Server returned HTTP response co
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)
Unknown said…
getting error like.....
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)
Unknown said…
sir it is not working for me .. however it is not showing error.
Unknown said…
SIR
Your code on way2sms not working for me!

please help my mca project
75% complete plese ........
email: g.satheesh48@gmail.com

any one please
Virender Singh said…
Hi Satheesh kumar,


These are some refernces for SMS APi Hope this will help you
FullonSMS API
FullonMS API Source Code
Unknown said…
can u please tell me ,send SMS without using from address,but using java code
Unknown said…
Hi,

The above code is giving me an error
Exception in thread "main" java.net.UnknownHostException: ubaid.tk
HIND said…
how can i link with acme software
HIND said…
This comment has been removed by the author.
Praneeth Damera said…
Hi all,

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
Praneeth Damera said…
Hi all,

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
kcr banglore said…
hi Sir,this is my code

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.
Unknown said…
Great piece of information i have solved my problem by using the method which you have give thanks for sharing the article Bulk sms
HIND MOBILES said…
This comment has been removed by the author.