How can I send SMS?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Pras_K
Posted On:   Wednesday, February 11, 2004 08:50 PM

Is there any way that I can write an application
which can send SMS from websit to mobile WITH USING JUST
J2SE apis?
Please guide me

Re: How can I send SMS?

Posted By:   Adam_Flint  
Posted On:   Wednesday, March 31, 2004 03:56 AM

Yes, there is, but you need to find yourself an SMS provider that has an HTTP interface to their software. If you can find one, you can simply write some code to make an HttpConnection to the remote provider, giving information on the SMS in the query string.

Below is some sample code. The url object contains the full URL to the SMS service provider, including our account user id and password, the SMS number to send to and the message. The first section of the code is to get through our firewall, so if you don't have a firewall, you don't need this.


URL url = "http://www.smsprovider.com?...";

// Set up our authentication
String auth = "username:password";
String smsAuthentication = "Basic " + new sun.misc.BASE64Encoder().encode(auth.getBytes());
System.setProperty("http.proxySet","true");
System.setProperty("http.proxyHost", getProxyLocation() );
System.setProperty("http.proxyPort", getProxyPort() );

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("Proxy-Authorization", smsAuthentication);

// Wierdness. We have to do this otherwise the SMS does not get
// delivered to the phone. I think that this is because the
// operation is a GET, and if we don't actually retrieve the
// information that has been broadcast, the transaction will
// not be complete.
int smsResponse = conn.getResponseCode();
conn.disconnect();
About | Sitemap | Contact