Java

To send SMS with Java, you can use one of the following methods:

1. Using URL Class

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

String username = "233xxxxxx"; // Your username
String apikey = "xxxxxx"; // ApiKey
String recipient = "233xxxxxx,233xxxxxx,233xxxxxx"; // MSIDSN (Number of the recipient in the International format)
String senderid = "ASPSMS"; // Sender ID
String msg = "Test Message JAVA"; // Message content
String authmode = "http"; // Mandatory (DO NOT CHANGE - Case Sensitive)

String urlParameters = "username=" + username + "&apikey=" + apikey + "&senderid=" + senderid + "&dest=" + recipient + "&msg=" + msg + "&authmode=" + authmode;
String request = "http://aspsmsapi.com/http/sendsms.aspx";

URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("charset", "utf-8");
connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
connection.setUseCaches (false);

DataOutputStream wr = new DataOutputStream(connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
connection.disconnect();

 

2. Using HTTPClient

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import org.apache.http.client.HttpClient;

// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://aspsmsapi.com/http/sendsms.aspx");

try {
// Build the chain of variables
List<namevaluepair> nameValuePairs = new ArrayList<NameValuePair>(6); // Nombre de paramètres à utiliser
nameValuePairs.add(new BasicNameValuePair("username", "233xxxxxx")); // Votre nom d'utilisateur
nameValuePairs.add(new BasicNameValuePair("apikey", "xxxxxx")); // Votre clé API
nameValuePairs.add(new BasicNameValuePair("senderid", "ASPSMS")); // Identifiant d'envoi
nameValuePairs.add(new BasicNameValuePair("dest", "233xxxxxx,233xxxxxx,233xxxxxx")); // Destinataire
nameValuePairs.add(new BasicNameValuePair("msg", "Test Message")); // Message
nameValuePairs.add(new BasicNameValuePair("authmode", "http")); // Obligatoire. Ne pas modifier
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Encoder les paramètres

// RUN the Application using POST Method
HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
// Action if request fails
} catch (IOException e) {
// TODO Auto-generated catch block
}
The new disc fly replica watches collection series ladies watch incorporates many replica watch modern and fashionable aesthetic elements in the classic design. Available in 39mm and 36mm sizes, the watch is fake replica watches available in a variety of materials with replica rolex a rich palette of colours.