JAVA sample code to use Reson8 SMS API
public static String SendSMS(String api_url, String username, String password, String msg_body, String msg_encoding, String country_code, String area_code, String recipients, String msg_header) throws Exception
{
String response = null;
URL url;
HttpURLConnection connection = null;
try {
url = new URL(api_url);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form
-urlencoded");
String urlParameters = "SenderName=" + URLEncoder.encode(username, "U
TF-8")
+ "&Password=" + URLEncoder.encode(password, "UTF-8")
+ "&MessageBody=" + URLEncoder.encode(msg_body, "UTF-8")
+ "&Encoding=" + URLEncoder.encode(msg_encoding, "UTF-8")
+ "&CountryCode=" + URLEncoder.encode(country_code, "UTF-8")
+ "&AreaCode=" + URLEncoder.encode(area_code, "UTF-8")
+ "&MessageRecipients=" + URLEncoder.encode(recipients, "UTF-8")
+ "&MsgHeader=" + URLEncoder.encode(msg_header, "UTF-8")
+ "&MCC=MNC=";
connection.setRequestProperty("Content-Length",
Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
wr=null;
BufferedReader rd = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String line;
StringBuffer responseBuffer = new StringBuffer();
while ((line = rd.readLine()) != null) {
responseBuffer.append(line);
responseBuffer.append('\r');
}
response=responseBuffer.toString();
rd.close();
rd=null;
}
finally
{
if (connection != null) { connection.disconnect(); connection = null; }
}
return response;
}