Ich versuche sms mit Twilio zu senden. Ich verwende den in dieser post angegebenen Code. Aber ich bekomme Antwort-Code als 201 statt 200. Auch die Antwort <?xml version='1.0' encoding='UTF-8'?>
ist seltsam. Gibt es einen Fehler im Code oder in den Anmeldeinformationen?SMS senden mit Twilio android
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
private String resp;
@Override
protected String doInBackground(String... params) {
try{
String twilioSID="XYZ";
String twilioSecret="ABC";
String urlStr = "https://"+twilioSID+":"+twilioSecret+"@api.twilio.com/2010-04-01/Accounts/"+twilioSID+"/SMS/Messages";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(urlStr);
String base64EncodedCredentials = "Basic "
+ Base64.encodeToString(
("XYZ" + ":" + "ABC").getBytes(),
Base64.NO_WRAP);
httppost.setHeader("Authorization", base64EncodedCredentials);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("From", "+12389234455"));
nameValuePairs.add(new BasicNameValuePair("To", "+918423664906"));
nameValuePairs.add(new BasicNameValuePair("Body", "Welcome to Twilio"));
httppost.setEntity(new UrlEncodedFormEntity(
nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
System.out.println("sammy_response_code "+status);
HttpEntity entity = response.getEntity();
if(entity != null){
resp = EntityUtils.toString(entity);
}
}catch (Exception e){
System.out.println("sammy_Exception "+e);
}
return resp;
}
@Override
protected void onPostExecute(String result) {
//pd.dismiss();
System.out.println("sammy_response "+result);
}
}
https://www.twilio.com/blog/2016/05/how-to-send-an-sms-from-android.html –