unable to send sms using nexmo or thilio

I was trying to send sms using java and for that I first tried with thilio.But I got error which is mentioned at the bottom.Then i downloaded,created an account in nexmo but again i get the same error.Please anybody those who had already worked on the above two can tell me why this issue come.

import com.nexmo.messaging.sdk.NexmoSmsClient;
import com.nexmo.messaging.sdk.SmsSubmissionResult;
import com.nexmo.messaging.sdk.messages.TextMessage;

public class SendTextMessage {

    public static final String API_KEY = "apikey";
    public static final String API_SECRET = "apisecret";

    public static final String SMS_FROM = "singapore_number";// as i use my office number so can not disclose it
    public static final String SMS_TO = "singapre_number";
    public static final String SMS_TEXT = "Hello World!";

    public static void main(String[] args) {

        // Create a client for submitting to Nexmo

        NexmoSmsClient client = null;
        try {
            client = new NexmoSmsClient(API_KEY, API_SECRET);
        } catch (Exception e) {
            System.err.println("Failed to instanciate a Nexmo Client");
            e.printStackTrace();
            throw new RuntimeException("Failed to instanciate a Nexmo Client");
        }

        // Create a Text SMS Message request object ...

        TextMessage message = new TextMessage(SMS_FROM, SMS_TO, SMS_TEXT);

        // Use the Nexmo client to submit the Text Message ...

        SmsSubmissionResult[] results = null;
        try {
            results = client.submitMessage(message);
        } catch (Exception e) {
            System.err.println("Failed to communicate with the Nexmo Client");
            e.printStackTrace();
            throw new RuntimeException("Failed to communicate with the Nexmo Client");
        }

        // Evaluate the results of the submission attempt ...
        System.out.println("... Message submitted in [ " + results.length + " ] parts");
        for (int i=0;i<results.length;i++) {
            System.out.println("--------- part [ " + (i + 1) + " ] ------------");
            System.out.println("Status [ " + results[i].getStatus() + " ] ...");
            if (results[i].getStatus() == SmsSubmissionResult.STATUS_OK)
                System.out.println("SUCCESS");
            else if (results[i].getTemporaryError())
                System.out.println("TEMPORARY FAILURE - PLEASE RETRY");
            else
                System.out.println("SUBMISSION FAILED!");
            System.out.println("Message-Id [ " + results[i].getMessageId() + " ] ...");
            System.out.println("Error-Text [ " + results[i].getErrorText() + " ] ...");

            if (results[i].getMessagePrice() != null)
                System.out.println("Message-Price [ " + results[i].getMessagePrice() + " ] ...");
            if (results[i].getRemainingBalance() != null)
                System.out.println("Remaining-Balance [ " + results[i].getRemainingBalance() + " ] ...");
        }
    }

}

error is as follows

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
    at SendTextMessage.main(SendTextMessage.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 1 more

Line 32 means this line client = new NexmoSmsClient(API_KEY, API_SECRET);


Why are you trying to use libraries? You can generally send SMS texts through email, as long as you know the carrier. Usually it's number@carrier.com or something like that.

Here's a site with a list of carrier addresses: http://20somethingfinance.com/how-to-send-text-messages-sms-via-email-for-free/


It looks like the Nexmo lib you are using has an external dependency that you didn't copy over.

From the Nexmo library documentation page:

Installation

You need to copy the nexmo-sdk.jar to your application and ensure that it is in your classpath. Additionally, there are some library dependencies under the /lib dir that must also be copied to your applications classpath if they are not already there.

So, look in the /lib directory of the SDK zipfile you downloaded, and copy those files wherever you put nexmo-sdk.jar

链接地址: http://www.djcxy.com/p/5648.html

上一篇: Laravel 5应用程序不断使用旧的数据库连接

下一篇: 无法使用nexmo或thilio发送短信