Java

Pour envoyer des SMS avec Java, vous pouvez utiliser l'une des methodes suivantes :

1. En utilisant la classe URL

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

String username = "228xxxxxx"; // Votre nom d'utilisateur
String apikey = "xxxxxx"; // Votre clé API
String recipient = "228xxxxxx,228xxxxxx,228xxxxxx"; // Destinataire au format international
String senderid = "ASPSMS"; // Sender ID
String msg = "Test Message JAVA"; // Message
String authmode = "http"; // Obligatoire. Ne pas modifier

// Construire la chaine des variables
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. En utilisant 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 {
// Construire la chaine des variables
List<namevaluepair> nameValuePairs = new ArrayList<NameValuePair>(6); // Nombre de paramètres à utiliser
nameValuePairs.add(new BasicNameValuePair("username", "228xxxxxx")); // 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", "228xxxxxx,228xxxxxx,228xxxxxx")); // 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

// Executer la requete POST
HttpResponse response = httpclient.execute(httppost);

} catch (ClientProtocolException e) {
// Action si la requete échoue
} 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.