Home Answers Viewqa Java-Beginners Code to Send SMS From PC to Mobile using Internet

 
 


sujay
Code to Send SMS From PC to Mobile using Internet
0 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Vector;

public class SMS 
{
public static void send(String uid, String pwd, String phone, String msg)  throws Exception 
{
    if ((uid == null) || (uid.length() == 0)) 
    {
        throw new IllegalArgumentException("User ID should be present.");
    }

    uid = URLEncoder.encode(uid, "UTF-8");

    if ((pwd == null) || (pwd.length() == 0)) 
    {
        throw new IllegalArgumentException("Password should be present.");
    }
    pwd = URLEncoder.encode(pwd, "UTF-8");

    if ((phone == null) || (phone.length() == 0)) 
    {
        throw new IllegalArgumentException("At least one phone number should be present.");
    }
    if ((msg == null) || (msg.length() == 0)) 
    {
        throw new IllegalArgumentException("SMS message should be present.");
    }
    msg = URLEncoder.encode(msg, "UTF-8");

    Vector numbers = new Vector();

    if (phone.indexOf(59) >= 0) 
    {
        String[] pharr = phone.split(";");
        for (String t : pharr)
        try 
        {
            numbers.add(Long.valueOf(t));
        }
        catch (NumberFormatException ex) 
        {
            throw new IllegalArgumentException("Give proper phone numbers.");
        }
    } 
    else 
    {
    try 
    {
        numbers.add(Long.valueOf(phone));
    } 
    catch (NumberFormatException ex) 
    {
        throw new IllegalArgumentException("Give proper phone numbers.");
    }
    }

    if (numbers.size() == 0) 
    {
        throw new IllegalArgumentException("At least one proper phone number should be present to send SMS.");
    }
    String temp = "";
    String content = "username=" + uid + "&password=" + pwd;
    URL u = new URL("http://www.way2sms.com/auth.cl");
    HttpURLConnection uc = (HttpURLConnection) u.openConnection();
    uc.setDoOutput(true);
    uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
    uc.setRequestProperty("Content-Length", String.valueOf(content.length()));
    uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    uc.setRequestProperty("Accept", "*/*");
    uc.setRequestProperty("Referer", "http://www.way2sms.com//entry.jsp");
    uc.setRequestMethod("POST");
    uc.setInstanceFollowRedirects(false);

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()), true);   
    pw.print(content);
    pw.flush();
    pw.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));

    while ((temp = br.readLine()) != null) 
    {
        System.out.println(temp);
    }

    String cookie = uc.getHeaderField("Set-Cookie");

    u = null;
    uc = null;
    for (Iterator localIterator = numbers.iterator();localIterator.hasNext();) 
    {
    long num = ((Long) localIterator.next()).longValue();

    content = "custid=undefined&HiddenAction=instantsms&Action=custfrom450000&login=&pass=&MobNo="+ num+ "&textArea="+ msg;
u = new URL("http://www.way2sms.com/FirstServletsms?custid=");
    uc = (HttpURLConnection) u.openConnection();
    uc.setDoOutput(true);
    uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
    uc.setRequestProperty("Content-Length", String.valueOf(content.getBytes().length));
    uc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
    uc.setRequestProperty("Accept", "*/*");
    uc.setRequestProperty("Cookie", cookie);
    uc.setRequestMethod("POST");
    uc.setInstanceFollowRedirects(false);
    pw = new PrintWriter(new OutputStreamWriter(uc.getOutputStream()),true);
    pw.print(content);
    pw.flush();
    pw.close();
    br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
    while ((temp = br.readLine()) != null);
    br.close();
    u = null;
    uc = null;
}

u = new URL("http://wwwa.way2sms.com/jsp/logout.jsp");
uc = (HttpURLConnection) u.openConnection();
uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
uc.setRequestProperty("Accept", "*/*");
uc.setRequestProperty("Cookie", cookie);
uc.setRequestMethod("GET");
uc.setInstanceFollowRedirects(false);
br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ((temp = br.readLine()) != null);
br.close();
u = null;
uc = null;
}
public static void main(String args[]) throws Exception
{
    SMS s=new SMS();
    SMS.send("9028192951","Sujay021991","9028192951","Hi How Are u !!");

}

}

I am Using This code to send SMS from PC to Mobile Phone But This code is throwing Following Exception.

***Exception in thread "main" java.io.IOException: Server returned HTTP response co
de: 400 for URL: http://www.way2sms.com/FirstServletsms?custid=
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1612)
        at SMS.send(SMS.java:117)
        at SMS.main(SMS.java:140)***

//Please any one tell me the solution for this.
//Your suggestions are always welcome.
View Answers









Related Pages:
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
Code to Send SMS From PC to Mobile using Internet
Code to Send SMS From PC to Mobile using Internet  import... !!"); } } I am Using This code to send SMS from PC to Mobile Phone... number should be present to send SMS."); } String temp
sms from pc to mobile
sms from pc to mobile  Sir I am developing a website and i need a code to send sms on any mobile from the wbesite.pls help me. thanx in advance
sms from pc to mobile
sms from pc to mobile  Sir I am developing a website and i need a code to send sms on any mobile from the wbesite.pls help me. thanx in advance
send sms from pc to mobile
send sms from pc to mobile  java program to send sms from pc to mobile
send sms from pc to mobile via gsm modem connected to pc in java
send sms from pc to mobile via gsm modem connected to pc in java  pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA
send sms from pc to mobile via gsm modem in java
send sms from pc to mobile via gsm modem in java  pls send me the code to send sms from pc to mobile via GSM modem programmed in JAVA........ can u pls help me to retrieve message from mobile to java program... import
sending sms from a remote pc - MobileApplications
sending sms from a remote pc  I have a remote pc that has a localhost server(tomcat).I want to know whether it is possible for me to send an sms from this server(my pc) to a mobile phone.If so can i have the sample code
how to send sms on mobile
how to send sms on mobile  send sms on mobile by using struts + spring
SMS receive and sending throught PC using GSM modem
SMS receive and sending throught PC using GSM modem  How to send and receive SMS from PC using GSM modem Want code please could some one helpme
How to send sms alerts to mobile using java?
How to send sms alerts to mobile using java?  Hi i have used the Code to send message on mobile using java code, it is not working - COM2...=" + 9100000000"; // the message center and also how this code is working
how to send sms on mobile and email using java code
how to send sms on mobile and email using java code  hi.... I am developing a project where I need to send a confirmation/updation msg on clients mobile and also an email on their particular email id....plz help me to find
how to send sms from my website to mobile of particular user.
how to send sms from my website to mobile of particular user.  i had... with their mobile number daily one health tip is to sent to their respective mobiles.. so can u tell the process and how to implemnt this using java
SMS Parsing
SMS Parsing  Hello Friends I am working on the code in which The text message(SMS) is send to receiver. There are two webpages UDHCSender &... as: sender mobile number SMS received but in the SMS received it shows
Sms Progam
Sms Progam  i have to send SMS from pc to mobile in my java program
sms - Java Server Faces Questions
sms  hello .... can any body tell me how to send sms from pc to mobile using java ..an if possible please give me the code in jsp..... my email id is:bharachaitanya@yahoo.co.in
Sms to mobile using java application
Sms to mobile using java application  Hi, i want to send sms to mobile using java application. But i dont have any idea for this procees. So kindly suggest me any ideas. regards vijayalakshmi
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)  How to send sms pc to mobile using JSP & Servelet
SMS Send and Recieve - JSP-Servlet
SMS Send and Recieve  How can i embedded SMS service to send and receive SMS from mobile to my application
Free PC to PC VoIP Providers
- Send an SMS (text) message from your mobile phone to our server containing... needed. That?s perfect solution when using a PC away from home.  Software... Free PC to PC VoIP Providers Babble Babble is a SIP-based internet
j2me sms coding - Java Beginners
j2me sms coding  please send me the source code to send sms and making a call from mobile
SMS sending questions using java - MobileApplications
SMS sending questions using java  am doing project sending SMS from... bulk SMS.am using mobile phone for sending SMS.is it possible sending bulk SMS or not.how can we send bulk SMS? am using some AT command for sending SMS .am
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)
TYBsc IT final project (MOBILE BASED SMS SEARCH ENGIN)  How to send and receive a msg from jsp servlet program to mobile phone using gsm vodafone... completed. so i requested to you pls answer my question. My project name is MOBILE
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
sms application - Development process
sms application  how to send sms from our website to mobile device  Hi friend, Code to help solve the problem : void send(byte data[]) { try { String dest= "sms://456475565:5001
swing sms
swing sms  HOW TO SEND SMS MESSAGE FROM SWING USING SQL DATABASE
java code for sending sms - JSP-Servlet
java code for sending sms  hello sir, I want a code for sending sms on mobile . please send me if u have this Thanks & regards Dharmendra
sendimg multi sms
sendimg multi sms  i want to send multiple sms from a distribution list decleared in the server...how do i connect my code to server
PC To Phone (PC-Phone) VoIP Directory
and businesses all over the world to make calls from their PC over the Internet to anywhere... generation communication tool that enables calls from a PC to either a fixed line... cost phone calls from your computer to any telephone(Pc to Phone) in the world
VoIP Mobile
completed the first successful transmission of a call from a mobile VoIP..., you'll be able to make unlimited calls from your mobile phone as well. U.S.-based... System iSkoot, a mobile Internet systems service provider of Cambridge, Mass
GPS Lost Mobile Phone Tracking Services
essential for you to keep eyeing your mobile phone from theft and from being misused... for the activation code, which we generate and sends, on the mobile of the subscriber.... For using our GPS based lost mobile tracking service, you must have a GPS
sending verification code to mobile using php
sending verification code to mobile using php  I had created a website and aim is to whoever the client register for site with their mobile number, verification code has to send to their respective mobiles.. so can u tell
PC To Phone (PC-Phone) VoIP Directory (Page 4)
the need to make calls using your PC. They are ideal for call shops, internet cafes... any country in the world. You can use our PC to Phone dialer from any internet... PC to talk longer (and save more) while making and receiving calls from regular
Sending SMS From Java Programs
Sending SMS From Java Programs  I want to develop and application to send sms from my computer, can someone please help me, like tell me where to start and what i need
Windows 8 PC Setting Step by Step Guide
are using any metered internet connection. Step 13: In ease...Until now the PC users were familiar with the control panel to access the PC... a new hub called 'PC Settings' that allows you to configure you PC as per your
PC To Phone (PC-Phone) VoIP Directory (Page 3)
extremely low rates! Pc-to-phone calls from your computer to any telephone or cell... be used from any computer connected to internet (minimum connection speed - 28.8... you make and receive calls from any mobile phone or landline. 
PC To Phone (PC-Phone) VoIP Directory (Page 5)
and make high quality, low cost long distance calls from your PC or your Phone... phones! WebPhone Call anyone, anywhere from your PC with WebPhone! You?ll...PC To Phone (PC-Phone) VoIP Directory (Page5) MediaRing MediaRing® PC Phone
RMI in internet - RMI
for controlling a PC from a remote location in Java. communication is done through internet. so is it possible to use RMI, or Sockets for internet communication? can we use RMI to communicate with any host connected to internet using it's IP
Mobile J2ME Game Development Services, J2ME Mobile Game Application Solutions, Mobile Games Development
Mobile J2ME Game Development J2ME Mobile Games Development Solutions from Rose... this type of games SMS are send to game server and in return game server sends back.... Browser games: using mobile phone's built-in micro browser users play
Mobile Application Development
design, develop code, test and finally release the client mobile programming... to enables us to send you quote.   Development of Mobile... newspapers using mobile platform. We help our clients in developing
Mobile Commerce,M-Commerce Services,Mobile Commerce in India,Advantages and History of Mobile Commerce
the money by accessing wireless internet service on the mobile handset itself... voice calling or via Short Message Services (SMS) services. WAP based mobile... using mobile commerce facilities. Banks also provide round the clock customer
sms(gsm) - MobileApplications
sms(gsm)  I heard that using GSM we can send only 10sms per second. Is it rigt? is there any other way so that we can send 250 SMS per second
Java SMS Progam
Java SMS Progam  Hai to all, I have to send SMS alerts in my applicaton in java technology with out using any gateways and GSM Modems. Thanks
Java as an Internet Language
; makes java a most suited internet language. Support to java enabled Mobile devices... Java as an Internet Language     ... a general purpose language that had many features to support it as the internet
How to send message in struts on mobile - Struts
How to send message in struts on mobile  Hello Experts, How can i send messages on mobile i am working on strus application and i want to send message from jsp
Getting and sending data to and from mobile and the system
Getting and sending data to and from mobile and the system  Hi, For getting and sending data to mobile from system.make system is a server.From mobile send a request to the server and get response.Then process the response
Mobile Software Development Solutions
development for iPhone, Smartphone and Pocket PC using C#, C... applications in .Net and Java Mobile payment services, SMS...Mobile Software Development Rose India's Mobile Software
how to take backup of phone to pc using java code
how to take backup of phone to pc using java code  i want to take the backup of phone data in my pc and also provide the restore functionality,and i want to do it using java program,so can anyone help me

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.