12.07.2015 Views

NetCom SMS Bedrift API Technical Documentation

NetCom SMS Bedrift API Technical Documentation

NetCom SMS Bedrift API Technical Documentation

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>NetCom</strong> <strong>SMS</strong> <strong>Bedrift</strong> <strong>API</strong><strong>Technical</strong> <strong>Documentation</strong>8. Sample Java client//******************************************************************************//**//** Module name : SmsSendClient.java//** Author : <strong>NetCom</strong>//** Created : Mar 2002//** Version : 1.0//******************************************************************************import java.net.*;import java.io.*;import org.w3c.tools.codec.Base64Encoder;//** ---------------------------------------------------------------------------//** Class : SmsSendClient//** Extends : None//** Implements : None//** Visibility : Public//** Description : A simple application demonstrating <strong>SMS</strong> send function//** ---------------------------------------------------------------------------public class SmsSendClient{//** -------------------------------------------------------------------------//** Constants **//** -------------------------------------------------------------------------private static final String sUser = "netcom";private static final String sPassword = "fgSds42k";private static final String sUrl = "http://localhost:8080/sms/send";private static final String sUsage = "Usage: SmsSendClient ";//** -------------------------------------------------------------------------//** main()//** -------------------------------------------------------------------------//** Send <strong>SMS</strong> using HTTP GET request.//** -------------------------------------------------------------------------public static void main(String sArgs[]){if (sArgs.length != 2){System.out.println(sUsage);System.exit(0); }}try{// prepare requestString sNumber = sArgs[0];String sMessage = sArgs[1];String sRequest = sUrl + "?" + "number=" + sNumber +"&" + "message=" + URLEncoder.encode(sMessage);URLConnection conn = new URL(sRequest).openConnection();// set authorization headerBase64Encoder enc = new Base64Encoder(sUser + ":" + sPassword);String sAuthHeader = "Basic " + enc.processString();conn.setRequestProperty("Authorization",sAuthHeader);// issue requestBufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)conn.getContent()));// read responseString sLine = null;while ((sLine = reader.readLine()) != null)System.out.println(sLine);}catch (Exception e) { e.printStackTrace(); }} // class SmsSendClientPage 13 of 13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!