Sending SMS

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

public class SMSSender {

public String sendSms(String sToPhoneNo,String sMessage) {
try {
// Construct data
String data = “username=” + URLEncoder.encode(“username****”, “UTF-8”);
data += “& password =” + URLEncoder.encode(“password****”, “UTF-8”);
data += “&numto=” + URLEncoder.encode(sToPhoneNo, “UTF-8”);
data += “&data1=” + URLEncoder.encode(sMessage, “UTF-8”);
data += “&senderid=” + URLEncoder.encode(“senderid”, “UTF-8”);
data += “&type=” + URLEncoder.encode(“sendparam”, “UTF-8”);

// Send data
URL url = new URL(“https://api.sendmode.com/httppost.aspx”);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
String sResult=””;
while ((line = rd.readLine()) != null) {
// Process line…
sResult=sResult+line+” “;
}
wr.close();
rd.close();
return sResult;
} catch (Exception e) {
System.out.println(“Error SMS “+e);
return “Error “+e;
}