6dc0 SMS Gateway - Cpp SMS API, c++ HTTP SMS example

                

Search the manual:

Overview Quick start Download Manual How to buy FAQ Contact Us
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

SMS Gateway SMS Gateway Home

  Product Manual
  Introduction
  SMS technology
  Installation Guide
  User Guide
  Developers Guide
  Tutorials
  ASP SMS API
  PHP SMS API
  HTTP SMS API
  SQL SMS API
  C Sharp SMS API
  AJAX SMS API
  Delphi SMS API
  Cpp SMS API
  c++ HTTP SMS example
  Java SMS API
  VB.NET SMS API
  Python SMS API
  Perl SMS API
  TCL/TK SMS API
  Coldfusion SMS API
  VB 6 SMS API
  Examples and Solutions
  Appendix
  FAQ
  Feature list
  Commercial Information
  Search
 



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.


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

Webphone solutions:
- Adobe Flash video phone
- Silverlight video phone
- Web to web calls
- Web to VoIP calls

Custom SIP clients:
- Silverlight SIP VoIP client
- Flash SIP VoIP client
- C# .net SIP VoIP client
- ASP .net SIP VoIP client
- Web based SIP VoIP client

Custom VoIP solutions:
- VoIP SIP softphones
- VoIP call center clients
- VoIP IVR systems
- VoIP predictive dialer systems
- VoIP auto dialer systems
- VoIP call assistant
- VoIP call recording systems
- VoIP intercom solutions

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

Introduction

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

#include<iostream>
#include<sstream>
#include<windows.h>
#include<wininet.h>

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,
        INTERNET_SERVICE_HTTP, 0, 0);

        // Open the HTTP request
        HINTERNET sess = HttpOpenRequest(conn, "GET", url.str().c_str(), "HTTP/1.1",
        NULL, NULL, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);

    // 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;
        }

        system("pause");
}


// 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";
                        else
                        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 - 2013 Ozeki Informatics Ltd.
All rights reserved

Software PBX for Windows | VoIP SDK   |   Legal information   |   Privacy policy   |   Terms of use
Please, address your inquiries to info@ozekisms.com


0