Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending to Timnet doesn't work #40

Open
arocketman opened this issue Jun 19, 2015 · 1 comment
Open

Sending to Timnet doesn't work #40

arocketman opened this issue Jun 19, 2015 · 1 comment

Comments

@arocketman
Copy link

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)

@lacostenycoder
Copy link

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?

@typpo typpo changed the title Trying to send a SMS from Java Sending to Timnet doesn't work Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants