Once upon a time in the first company that I start my job as Java Developer, I got a task, Send SMS to our clients. Greate! I think it was Java 5 or 6 I'm not sure about it, but I'm sure our SMS provider used legacy methods to get SMS from us; I got this source from Mr. Majidi (one of kind person of that company, and also head of another team of it), and now I decide to share it here for you, may someday help somebody:
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class SMS {
public static void sendSms(String mobile, String msg) throws Exception {
String url = "{SERVER_URL}";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("accept-charset", "UTF-8");
String urlParam =
"HEADER={YOUR_SMS_NUMBER}&DESTINATION=" + "{COUNTRY_CODE}" + mobile.substring(1) +
"&MESSAGEID=1&MESSAGE=" + msg + "&DCS=8";
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(wr, "UTF-8"));
writer.write(urlParam);
writer.close();
wr.close();
int responseCode = con.getResponseCode();
BufferedReader in =
new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
}
}