Ozeki NG SMS Gateway logo OZEKI NG SMS Gateway
"The World's most reliable SMS gateway software!"

OZEKI NG SMS Gateway - Product Guide

Cpp SMS API Contents | SearchJava SMS API

Home > Product Manual > Developers Guide > Cpp SMS API > c++ HTTP SMS example


Automated phone calls?
Ozeki Phone System XE VoIP PBX software is an advanced PBX built for automated voice calls and 2 way SMS messaging. It has outstanding APIs for software developers. It can be used for:

Phone calls from SQL
Phone calls from HTTP
Voice and SMS applications

Callcenter developers
If you are working on telephone solutions, please check out the Ozeki VoIP SIP SDK.
It can be used to create VoIP client and server software.

Contact Us!
If you wish to get further information, do not hesitate to contact us!

E-mail: info@ozekisms.com

If you have a technical question, please submit a support request on-line.

Using the HTTP C++ SMS API

This is an example for Visual Studio 2008 developers on how to send SMS from C++ applications using HTTP reqest. The example is based on the Ozeki HTTP SMS API. For a higher performance C++ SMS source code, please visit the C++ SMS SDK that uses a TCP/IP socket to send and receive SMS messages.
Download: cpp-sms-source-http.zip


The Ozeki HTTP SMS Api is an excellent solution to post SMS messages to the Ozeki NG SMS Gateway through the network. To use this solution first you need to install and configure Ozeki NG SMS Gateway in one of your computers, then you can use the example bellow to send SMS messages through it from any C++ application. This example posts SMS messages through HTTP to the gateway. The Ozeki gateway can convert these posts and forward your SMS messages through SMPP, CIMD2, UCP to SMS service providers or it can operate GSM modems to send your SMS messages using AT commands (Figure 1).

Figure 1 - HTTP SMS sending from C++

Source code for C++ SMS sending through HTTP


using namespace std;

string encode(string url);

int main(int argc, char** argv)
        // Ozeki NG SMS Gateway's host
        // and port.
        string host       = "localhost";
        int port          = 9502;

        // Username
        // and password.
        string username   = "admin";
        string password   = "abc123";

        // Message
        string message    = "Test message!";

        // Originator's phone number.
        string originator = "+001111111";

        // Recipient(s) phone number.
        //        If You want to send message to multiple recipients, separate them with coma.
        // (don't use space character!) Ex: "+002222222,+003333333,+004444444"
        string recipient  = "+002222222";

        // Preparing the HTTPRequest url
        stringstream url;
                url << "/api?action=sendmessage&username=" << encode(username);
                url << "&password=" << encode(password);
                url << "&recipient=" << encode(recipient);
                url << "&messagetype=SMS:TEXT&messagedata=" << encode(message);
                url << "&originator=" << encode(originator);
                url << "&responseformat=xml";

        // Create socket.
        HINTERNET inet = InternetOpen("Ozeki", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

        // Open connection and bind it to the socket.
        HINTERNET conn = InternetConnect(inet, host.c_str() , port, NULL, NULL,

        // Open the HTTP request
        HINTERNET sess = HttpOpenRequest(conn, "GET", url.str().c_str(), "HTTP/1.1",

    // Check errors
        int error = GetLastError();
        if(error == NO_ERROR)
                // Send HTTP request.
                HttpSendRequest(sess, NULL, 0, NULL,0);

                // Receive HTTP response.

                int size = 1024;
                char *buffer = new char[size + 1];
                DWORD read;
                int rsize = InternetReadFile(sess, (void *)buffer, size, &read);
                string s = buffer;
                s = s.substr(0, read);

                // Check statuscode
                int pos = s.find("<statuscode>0</statuscode>");

                // If statuscode is 0, write "Message sent." to output
                // else write "Error."
                if(pos > 0) cout << "Message sent." << endl;
                else cout << "Error." << endl;


// encoding converts characters that are not allowed in a URL into character-entity equivalent.
string encode(string url)
        char *hex = "0123456789abcdef";
        stringstream s;

        for(unsigned int i = 0; i < url.length(); i++)
                byte c = (char)url.c_str()[i];
                if( ('a' <= c && c <= 'z')
                || ('A' <= c && c <= 'Z')
                || ('0' <= c && c <= '9') ){
                        s << c;
                } else {
                        if(c == ' ') s << "%20";
                        s << '%' << (hex[c >> 4]) << (hex[c & 15]);

        return s.str();

Dig deeper!
People who read this also read...

Next page: Java SMS API
Copyright © 2000- - Ozeki Ltd | info@ozeki.hu
Home > Product Manual > Developers Guide > Cpp SMS API > c++ HTTP SMS example
Legal | Privacy | Terms of use | 2377 | | Login