textbelt
textbelt copied to clipboard
Sending to Timnet doesn't work
Hello there, I am trying to send a SMS with Java. I haven't quite understood if I have to put the prefix in front of the number I am trying to send or not. Anyhow, here's the code I'm using:
URL url = new URL("http://textbelt.com/intl");
Map<String,Object> params = new LinkedHashMap<>();
params.put("number", "+39*******");
params.put("message", "hithere");
StringBuilder postData = new StringBuilder();
for (Map.Entry<String,Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}
byte[] postDataBytes = postData.toString().getBytes("UTF-8");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
for ( int c = in.read(); c != -1; c = in.read() )
System.out.print((char)c);
}
And I'm getting as response:
{
"success": true
}
Both with and without prefix. Yet no message is arriving to my phone. My carrier is TIM (which is listed as supported)
Not sure if this is the reason but if you try to go to http://timnet.com or http://www.timnet.com no dns. Checked http://www.who.is/dns/timnet.com and the ip addresses lead nowhere... so perhaps that's the problem?