Code to Send SMS From PC to Mobile using Internet

Code to Send SMS From PC to Mobile using Internet

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

July 5, 2012 at 1:40 PM

do you have a code written in c# that does the same fonctionalities ? thank you.. �©_�¨









Related Tutorials/Questions & Answers:
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
Advertisements
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
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
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 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
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
code to send sms alerts using jsp online
code to send sms alerts using jsp online  I am new to mobile aplication development. pls send me the code for sms alerts after clicking the button
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
how to send sms on mobile  send sms on mobile by using struts + spring
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
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
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
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
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
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
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
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
Sms Progam
Sms Progam  i have to send SMS from pc to mobile in my java program
How to download and save a file from Internet using Java?
How to download and save a file from Internet using Java?  How to download and save a file from Internet using Java
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:[email protected]
java code to send email using gmail smtp server
java code to send email using gmail smtp server  please send me the java code to send email using gmail smtp server. and how to send verification code
java source code to send group mails using struts2
java source code to send group mails using struts2  code to send group mails using struts2
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
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
j2me sms coding - Java Beginners
j2me sms coding  please send me the source code to send sms and making a call from mobile
SMS using Java
;This is regarding your post for sending SMS from a PC( http://www.roseindia.net/answers/viewqa/Java-Beginners/15745-Sms-to-mobile-using-java-application.html ) How...SMS using Java  I am having a concern , where is the main class
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
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
sir, how to convert excel file to csv file using java? please send me sample code.
sir, how to convert excel file to csv file using java? please send me sample code.  please send me sample code for converting excel file into csv file uisng java
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
ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking'
ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking'  ...: No module named 'odoo10-addon-sms-send-picking' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking' error
ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking'
ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking'  ...: No module named 'odoo10-addon-sms-send-picking' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-sms-send-picking' error
ModuleNotFoundError: No module named 'send-sms-freemobile'
ModuleNotFoundError: No module named 'send-sms-freemobile'  Hi, My... named 'send-sms-freemobile' How to remove the ModuleNotFoundError: No module named 'send-sms-freemobile' error? Thanks   Hi
pls send code
pls send code   pls send code for set database value into text box based on selected value in struts and jsp   use any database and get its code for getting values from google
Pls send code
Pls send code   I am Mohini Charankar suppose Name="Mohini" Edit Button Click on that I change my Name with "Mohini/" Save it and page refresh After... an error pls send code
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
finding java code on internet
finding java code on internet  Is there anybody to help me? i want to some java coding web sites.it is prerequest for me
send mail using JavaScript
send mail using JavaScript  How can we send mail using JavaScript?   Hi friends, You can not send email directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using
how to call from pc to telephone in java - MobileApplications
how to call from pc to telephone in java  Hi, presently I am working on "make a call from pc to telephone" in java. I am unable to procceed how to start. I am new this technoloy.Please give me some valuable suggestions how
plz send code for this
plz send code for this  Program to calculate the sum of two big numbers (the numbers can contain more than 1000 digits). Don't use any library classes or methods (BigInteger etc
how to generate reports from oracle database using jsp and ajax code
how to generate reports from oracle database using jsp and ajax code  ... sales report data from oracle database to jsp page please any one know how to do this send me a code to my email:[email protected] its a humble request my team
How to set attachment from browse button to send mails using java mail api
How to set attachment from browse button to send mails using java mail api   Hello Sir, I am making Email Sending app using java mail api in jsp and servlet in that i have to make attachment option available using

Ads