Sunday, June 26, 2011

Send SMS vis SMS Gateway using Java!

See this for details and signup: http://www.smsmatrix.com/?sms-gateway

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/**
 * The Class MailReader.
 *
 * @author Varra
 * @version 1.0
 */
public final class MailReader
{
   
    /**
     * The main method.
     *
     * @param args
     *            the arguments
     */
    public static void main(String[] args)
    {
        try
        {
            String MATRIXURL = "http://www.smsmatrix.com/matrix";
            String PHONE = "9551231331";
            String USERNAME = "v.rajareddy@hotmail.com";
            String PASSWORD = "prathap";
            String TXT = "This is a test, pls ignore";
           
            String q = "username=" + URLEncoder.encode(USERNAME, "UTF-8");
            q += "&" + "password=" + URLEncoder.encode(PASSWORD, "UTF-8");
            q += "&" + "phone=" + PHONE;
            q += "&" + "txt=" + URLEncoder.encode(TXT, "UTF-8");
           
            URL url = new URL(MATRIXURL);
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(q);
            wr.flush();
           
            BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            System.out.println("Matrix API Response :");
            while ((line = rd.readLine()) != null)
            {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

No comments:

Post a Comment