How to send sms to mobile from java code.... | Search |
NowSMS Support Forums ⬆ NowSMS Support - SMS Issues ⬆ Archive through August 22, 2012 ⬆ |
◄ ► |
Author | Message | |||
siva New member Username: Gudluri Post Number: 1 Registered: 02-2012 |
I tried below example for sending message to mobile from java code... but it shows connection failure exception.. please help me for sending message to mobile from java... import java.net.*; import java.io.*; import javax.swing.*; import javax.net.ssl.HttpsURLConnection; class sendSMS { public static void main(String args[]) { boolean debug=true; String phone =""; String message =""; String ppgHost ="http://localhost:8800/"; String username =""; String password =""; try { phone=URLEncoder.encode("7418674647", "UTF-8"); if(debug) System.out.println("phone------>"+phone); message=URLEncoder.encode("SendMsg via Now.SMS", "UTF-8"); if(debug) System.out.println("message---->"+message); } catch (UnsupportedEncodingException e) { System.out.println("Encoding not supported"); } String url_str=ppgHost+"?PhoneNumber="+phone+"&Text="+message; // String url_str=ppgHost+"?user="+username+"&password="+password+"&PhoneNumber="+phone+"& Text="+message; if(debug) System.out.println("url string->"+url_str); try { URL url2=new URL(url_str); HttpURLConnection connection = (HttpURLConnection) url2.openConnection(); connection.setDoOutput(false); connection.setDoInput(true); if(debug) System.out.println("Opened Con->"+connection); String res=connection.getResponseMessage(); if(debug) System.out.println("Get Resp ->"+res); int code = connection.getResponseCode () ; if ( code == HttpURLConnection.HTTP_OK ) { connection.disconnect() ; } } catch(IOException e) { System.out.println("unable to create new url"+e.getMessage()); } } // main } // class Thanks in Advance | |||
Des - NowSMS Support Board Administrator Username: Desosms Post Number: 3810 Registered: 08-2008 |
Well, let's start with the stupid question first ... Are you running NowSMS somewhere? The code refers to "localhost", so it is expecting to find NowSMS running on that same machine. If you are running NowSMS on that local machine, have you changed the port number for the web interface? Can you access it via a web browser? If you do not understand my response, please read this link: http://www.nowsms.com/faq/about -- Des NowSMS Support |