Advanced Services - SMS Connectivity

Java Sample application using HTTP to send a picture message

HSL Mobile Messaging

The following sample application written in Java sends a picture message to a single mobile telephone. The application uses HTTP to communicate with HSL's systems. To send to more than one mobile telephone at a time, separate each mobile number in the destaddr field by a comma (e.g. "447968000111,447720000111,3378100100").

import java.net.*;
import java.io.*;
import java.security.*;

public class SuperSimplePictureMessageHTTPExample {
    public static void main(String[] args) {
        try {
            // These variables fill out the various parts described in the
            // interface specification
            String host = "sms.haysystems.com";
            String port = "80";
            String action = "sendnok";
            String client_id = "<your client_id>";
            String type = "pg";
            String content = "50340a232043726561746564206279205061696e7420536";
            content += "86f702050726f20370a37322032380a0000000000000000000003";
            content += "ffffffffffffff00000000000000000000e000000000000000033";
            content += "8000000000000000cee00000000000000131b01f81f8fe7c0006c";
            content += "06c0600618630000f001e0600630230000e000e0600630030000e";
            content += "000e0600618030000e000e060061c030000e000e060060f030000";
            content += "e000e07ffe07830000e000e0600601c30000e000e0600600e3000";
            content += "0e000e0600600730000e000e0600600730000e000e06006207300";
            content += "80f001e0600630e301807c07c1f81fbf87ff801f1f00000000000";
            content += "0000ffe0000000000000003f80000000000000000e00000000000";
            content += "00000000000000000000000003ffffffffffffff0000000000000";
            content += "00000";
            String destaddr = "<some fully-qualified MSISDN>";
            String text = "this is a test message";
            String password = "<your password>";

            // Build and encode the URL.
            // Note we are careful to URL-encode the message content as it is
            // the only part of the URL likely to contain reserved characters.
            String url = "http://" + host + ":" + port + "/" + action;
            url += "/?client_id=" + client_id + "&destaddr=" + destaddr;
            url += "&type=" + type + "&content=" + content + "&text=";
            url += URLEncoder.encode(text, "UTF-8") + "&password=" + password;

            // Make a URL object, ready for the call
            URL urlObject = new URL(url);

            // Actually make a connection
            HttpURLConnection connection =
                (HttpURLConnection)urlObject.openConnection();
            connection.setDoInput(true);
            connection.connect();

            // Check the response
            int responseCode = connection.getResponseCode();
            if(responseCode == 200) {
                // Read the server's response
                BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));

                System.out.println("Submission result: " + in.readLine());
                in.close();

            } else {
                // There was an error
                System.err.println("Server responded with code " + responseCode);
            }

        } catch(Exception e) {
            System.err.println("Unable to make HTTP request due to an exception:");
            e.printStackTrace();
        }
    }
}

SuperSimplePictureMessageHTTPExample.java


Copyright © Hay Systems Ltd 2004

Owner: support@haysystems.com 20 September 2004

Sample code link | Developers section link