短信发送jar无法从终端工作

时间:2018-05-11 11:28:15

标签: java netbeans sms

我可以使用我的java类从Netbeans发送短信,但是当我尝试从终端/命令运行时,它无法正常工作。不会抛出任何错误。我已经尝试过编译不同的java版本。我在ubuntu 14工作,使用jdk 7 / 1.8。

String authkey = "abc";
String mobiles = mobile;
mobiles = Arrays.stream(mobiles.split(",")) .distinct() .collect(Collectors.joining(","));
String senderId = sid;
String message = msg;
String route="4"; //Transaction
URLConnection myURLConnection=null;
URL myURL=null;
BufferedReader reader=null;
String encoded_message=message.trim();
String mainUrl="example.com/api/sendhttp.php?";
StringBuilder sbPostData= new StringBuilder(mainUrl);
sbPostData.append("authkey=").append(authkey); 
sbPostData.append("&mobiles=").append(mobiles);
sbPostData.append("&message=").append(encoded_message);
sbPostData.append("&route=").append(route);
sbPostData.append("&sender=").append(senderId);

 mainUrl = sbPostData.toString();
 try
 {
//prepare connection
myURL = new URL(mainUrl);
myURLConnection = myURL.openConnection();
myURLConnection.connect();
reader= new BufferedReader(new InputStreamReader(myURLConnection.getInputStream()));
//reading response 
String response;
while ((response = reader.readLine()) != null) {
    //print response
    System.out.println(response);
}

//finally close connection
reader.close();
 } 
 catch (IOException e) 
 { 
 JOptionPane.showMessageDialog (null,"Could not send SMS"+e);                     
  }

0 个答案:

没有答案