String login = "ACCOUNT_SID" + ":" + "AUTH_TOKEN";
String base64login = new String(Base64.encodeBase64(login.getBytes()));
String phoneNumber = "+14222456789";
String messageText = "Hello, World!";
try {
Response response = Jsoup
.connect(
"https://api.twilio.com/2010-04-01/Accounts/{ACCOUNT_SID}/Messages.json")
.header("Authorization", "Basic " + base64login)
.timeout(10000).method(Method.POST).data("To", phoneNumber)
.data("From", "+14211456789").data("Body", messageText)
.execute();
if (response.statusCode() == 201) {
System.out.println("send message");
} else {
System.out.println("Message Send Failure");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
A blog about the use of educational technology in language learning and teaching
Sunday, August 21, 2016
Send sms via twilio api
Labels:
Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment