3

i am using way2sms api in my web application. Previously it was working fine but now it is not able to send sms. Can anyone tell me what must have gone wrong suddenly. Is the api outdated? or is there problems with the way2sms site or the gateway?

Kanchan Ruia
  • 331
  • 3
  • 6
  • 13
  • 1
    Don't you get any kind of error message or exception? – Joachim Sauer Jun 06 '12 at 06:40
  • i have used exception handling in my code and it says could not be send. Do you want me to post my code? – Kanchan Ruia Jun 07 '12 at 08:03
  • 1
    If "could not be send" is all you get, then you're doing it wrong. What is the exception type? What is the stack trace? What is the **exact** error message? Do you even *have* the stacktrace? Or does "used exception handling" mean you wrote `catch (Exception e) { System.out.println("could not be send"); }`? If so, please re-learn what exception **handling** means. – Joachim Sauer Jun 07 '12 at 10:10
  • Incomplete question.how can we tell what could have gone wrong suddenly unless you post some information relating it.Frame your questions properly – Suhail Gupta Jun 13 '12 at 16:25

1 Answers1

1

Here's some code I wrote, hopefully you'll find it useful.

import java.net.*;
import java.io.*;

public class SmsSender
{
  //Replace your way2sms username and password below
  static final String _userName = "your way2sms username";
  static final String _password = "your way2sms password";
  static final String _url = "http://ubaid.tk/sms/sms.aspx";
  static final String charset = "UTF-8";

  //to build the query string that will send a message
  private static String buildRequestString(String targetPhoneNo, String message) throws UnsupportedEncodingException
  {
    String [] params = new String [5];
    params[0] = _userName;
    params[1] = _password;
    params[2] = message;
    params[3] = targetPhoneNo;
    params[4] = "way2sms";

    String query = String.format("uid=%s&pwd=%s&msg=%s&phone=%s&provider=%s",
        URLEncoder.encode(params[0],charset),
        URLEncoder.encode(params[1],charset),
        URLEncoder.encode(params[2],charset),
        URLEncoder.encode(params[3],charset),
        URLEncoder.encode(params[4],charset)
        );
    return query;
  }

  public static void sendMessage(String reciever, String message) throws Exception
  {
    //To establish the connection and perform the post request
    URLConnection connection = new URL(_url + "?" + buildRequestString(reciever,message)).openConnection();
    connection.setRequestProperty("Accept-Charset", charset);

    //This automatically fires the request and we can use it to determine the response status
    InputStream response = connection.getInputStream();
    BufferedReader br = new BufferedReader(new InputStreamReader(response));
    System.out.println(br.readLine());
  }

  public static void main(String [] args)
    throws Exception
  {
    String testPhoneNo = "9876543210";
    String testMessage = "Sending Messages From java is not too hard";

    sendMessage(testPhoneNo,testMessage);
  }
}
nikhil
  • 8,925
  • 21
  • 62
  • 102
  • Yes it has stopped working for way2sms, you can try some other providers. The person who was providing the `api` has moved to a paid model and I haven't had the time to work on it to write an alternative API. Some other providers do work, you'll need to spend some time to figure which ones work and which ones don't. – nikhil Feb 28 '13 at 09:25
  • try this one http://ayushpateria.com/way2sms.php and I am not sure if the owner of this site stores credentials or not. – Yauraw Gadav Aug 06 '13 at 20:02
  • @nOiAd please check the link that you have posted. It seems to redirect back to way2sms – nikhil Aug 07 '13 at 04:27
  • Yes, The link just redirects the request. – Yauraw Gadav Aug 09 '13 at 08:51