Example code for SMS integration in language C++

Send SMS - HTTP/GET

                
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <string>
#include <locale>
#pragma comment(lib,"ws2_32.lib")
using namespace std;

string website_HTML;
locale local;


void get_Website(char *url );

int main ()
{
    //open website
    get_Website("http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message");

    //format website HTML
    for (size_t i=0; i<website_HTML.length(); ++i)
        website_HTML[i]= tolower(website_HTML[i],local);

    //display HTML
    cout <<website_HTML;

    cout<<"\n\n";



    return 0;
}



//***************************
void get_Website(char *url )
{
    WSADATA wsaData;
    SOCKET Socket;
    SOCKADDR_IN SockAddr;


    int lineCount=0;
    int rowCount=0;

    struct hostent *host;
    char *get_http= new char[256];

        memset(get_http,' ', sizeof(get_http) );
        strcpy(get_http,"GET / HTTP/1.1\r\nHost: ");
        strcat(get_http,url);
        strcat(get_http,"\r\nConnection: close\r\n\r\n");

        if (WSAStartup(MAKEWORD(2,2), &wsaData) != 0)
        {
            cout << "WSAStartup failed.\n";
            system("pause");
            //return 1;
        }

        Socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
        host = gethostbyname(url);

        SockAddr.sin_port=htons(80);
        SockAddr.sin_family=AF_INET;
        SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);

        cout << "Connecting to "<< url<<" ...\n";

        if(connect(Socket,(SOCKADDR*)(&SockAddr),sizeof(SockAddr)) != 0)
        {
            cout << "Could not connect";
            system("pause");
            //return 1;
        }

        cout << "Connected.\n";
        send(Socket,get_http, strlen(get_http),0 );

        char buffer[10000];

        int nDataLength;
            while ((nDataLength = recv(Socket,buffer,10000,0)) > 0)
            {
                int i = 0;

                while (buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r')
                {
                    website_HTML+=buffer[i];
                    i += 1;
                }
            }
        closesocket(Socket);
        WSACleanup();

            delete[] get_http;
}

Send SMS - Builder C++ 6 - HTTP/GET

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

#include <vcl.h>
#pragma hdrstop

#pragma comment(lib, "wininet.lib")

...

string host       = "api.labsmobile.com";
int port          = 80;

string username   = "YOUR USERNAME";
string password   = "YOUR PASSWORD";
string message    = "YOUR MESSAGE";
string originator = "DESTINATION PHONE NUMBER";
string recipient  = "YOUR SENDER";

stringstream url;
url << "/get/send.php?username=" << encode(username);
url << "&password=" << encode(password);
url << "&sender=" << encode(recipient);
url << "&msisdn=" << encode(originator);
url << "&message=" << encode(message);


// Create socket.
HINTERNET inet = InternetOpen("SendingSMSLabsMobile", 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("<code>0</code>");

        // If statuscode is 0, write "Message sent." to output
        // else write "Error."
        if(pos > 0){
          ShowMessage("Message sent.");
        }
        else{
          ShowMessage("Error.");
        }
}

Credit inquiry - HTTP/GET

                
#include <winsock2.h>
#include <windows.h>
#include <iostream>
#include <string>
#include <locale>
#pragma comment(lib,"ws2_32.lib")
using namespace std;

string website_HTML;
locale local;


void get_Website(char *url );

int main ()
{
    //open website
    get_Website("http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]");

    //format website HTML
    for (size_t i=0; i<website_HTML.length(); ++i)
        website_HTML[i]= tolower(website_HTML[i],local);

    //display HTML
    cout <<website_HTML;

    cout<<"\n\n";



    return 0;
}
  • contact form support

    Sign up!

    Create a user account and send your SMS messages in seconds. You will have all the functionalities and benefits in the same platform.

    Send from API and manage your account with our online application WebSMS.

    Create new account
  • TripMedic, Medical appointments abroad recommends LabsMobile

    Sending confirmations, evaluations and reminders for medical appointments via SMS.

    Watch more reviews
  • dashboard aplicación online

    Maximum reliability at the best price

    At LabsMobile we only offer direct routes of maximum reliability and quality. Enjoy our platform and all our services for the price of an SMS.

    Pay ONLY for sent messages.

    Check our rates
  • dashboard aplicación online

    Need more info? Contact us!

    Our technical department has professionals with years of experience and we have made multiple integrations.

    We guide and help you through the process.

    Request technical support
  • Create a personalized SMS sending

    This tutorial explains how to send SMS messages to a mobile phone database by customizing the message text with variables.

    Ir al tutorial
loader