n w    w w w w

baner

Knowledge is power, and what about sharing the power. CodeGlobe is an open space where we programmers and techies share what we got special with us, The experience we got over years through our profession, the magical touch we made in solving logical hurdles, the new solutions we developed ourselves where others hesitated, alike all these, each and every bit of knowledge we got, let's just share with our pals. All we have to posses is just a mind to speak out and listen others. Registrations are open and hope you won't fail in grabbing this opportunity to become a Codeglober.


 


 

You are here:   Home / API / Way2SMS / Way2SMS API
large small default
Way2SMS API Print E-mail
Written by Nimish T   
Tuesday, 16 March 2010 18:58
Article Index
Way2SMS API
Way2SMS Java code Explanation
Way2SMS C# code
Way2SMS PHP code
All Pages

Zion SMS Mania 1.1 beta  our example Application

Download Developed by CodeGlober  Joji

Website URL: xpedition009

 

This article will give you a brief introduction regarding the implementation of way2sms API.We  providing you various flavors of the API in PHP, C# and  Java etc which will helps  you to integrate the free SMS functionlity with in your application using your user credentials in Way2SMS. This program using very simple technique like http client connection to establish a connection with the way2sms website. If you get the thinks better means you can write your own API for many of your favourite application which helps you to integrate that with in your system.

important thing begins from the. This is just like a small type of hacking.

Java Source code

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 IOException {
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://wwwa.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://wwwg.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://wwwa.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;
}
}

 

 



Comments (3)
  • harini  - hi

    hi how r u

  • kadewars sunil

    :) thanks

  • Anonymous

    :D :angry: :angry-red: :evil: :idea:

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.
Last Updated on Thursday, 18 March 2010 13:00