Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sujay
Code to Send SMS From PC to Mobile using Internet
0 Answer(s)      2 years and 7 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.

Advertisement
View Answers

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
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 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
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 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
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 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
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 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
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
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 Progam
Sms Progam  i have to send SMS from pc to mobile in my java program
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
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
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
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 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
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
j2me sms coding - Java Beginners
j2me sms coding  please send me the source code to send sms and making a call from 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
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
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
 

 

 

DMCA.com