Here we provide you sample source codes that might help you to jump-start with using SMSEagle’s HTTP API.

The code snippets are only examples of possible use.

PHP Send SMS using HTTP GET

    $base_url = 'http://url-of-smseagle/index.php/http_api/send_sms';
    $params = array(
        'login' => 'john',           
        'pass' => 'doe',        
        'to'       => '1234567',    
        'message'  => "my message", 
    );
    $data = '?'.http_build_query($params);
    $ret = fopen($base_url.$data,'r');
    $result = fread($ret,1024);
    fclose($ret);
    if (substr($result,0,2) == "OK") {
    echo "Message has been sent successfully!";
    } else {
    echo "Send message failed!";
    }

C# Send SMS using HTTP GET

using System.Net;
using System.IO;
string baseUrl ="http://url-of-smseagle/index.php/http_api/send_sms";
WebClient client = new WebClient();
client.QueryString.Add("login", "john");
client.QueryString.Add("pass", "doe");
client.QueryString.Add("to", "1234567");
client.QueryString.Add("message", HttpUtility.UrlEncode("My message"));
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
Stream receivedStream = client.OpenRead(baseUrl);
StreamReader reader = new StreamReader(receivedStream);
string result = reader.ReadToEnd();
receivedStream.Close();
reader.Close();
return result;

Java Send SMS using HTTP GET

import java.io.*;
import java.net.*;
HttpURLConnection conn;
BufferedReader reader;
String line;
String result = "";
URL baseUrl ="http://url-of-smseagle/index.php/http_api/send_sms";
String charset = "UTF-8";
String query = String.format("login=%s&pass=%s&to=%s&message=%s&format=php",
URLEncoder.encode("john", charset),
URLEncoder.encode("doe", charset),
URLEncoder.encode("1234567", charset),
URLEncoder.encode("My message", charset)
);
url = new URL(baseUrl + "?" + query);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
result += line;
}
reader.close();
conn.disconnect();
System.out.println(result);
return result;

Java Send SMS using JSON-RPC

import java.io.*;
import java.net.*;
import net.sf.json.JSONObject;
HttpURLConnection connection = null;
OutputStreamWriter writer = null;
BufferedReader reader = null;
StringBuilder sbuilder = null;
URL serverAddress = null;
serverAddress = new URL("http://url-of-smseagle/index.php/jsonrpc/sms");
connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.connect();
//
writer = new OutputStreamWriter(connection.getOutputStream());
JSONObject parameters=new JSONObject();
parameters.put("login", "john");
parameters.put("pass", "doe");
parameters.put("to", "481234567");
parameters.put("message", "My message");
JSONObject json=new JSONObject();
json.put("method", "sms.send_sms");
json.put("params", parameters);
System.out.println(json);
writer.write(json.toString());
writer.close();
//
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
sbuilder = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sbuilder.append(line + 'n');
}
connection.disconnect();
reader.close();
String result = sbuilder.toString();
System.out.println(result);
return result;

Python Send SMS using HTTP GET

import urllib
import urllib2
base_url = 'http://url-of-smseagle/index.php/http_api/send_sms'
query_args = { 'login':'john', 'pass':'doe', 'to':'1234567', 'message':'My message' }
encoded_args = urllib.urlencode(query_args)
url = base_url + '?' + encoded_args
result = urllib2.urlopen(url).read()

VB.NET Send SMS using HTTP GET

Imports System.Net
Imports System.IO
Dim baseUrl as String = "http://url-of-smseagle/index.php/http_api/send_sms"
Dim client as WebClient = New WebClient()
client.QueryString.Add("login", "john")
client.QueryString.Add("pass", "doe")
client.QueryString.Add("to", HttpUtility.UrlEncode("1234567"))
client.QueryString.Add("message", HttpUtility.UrlEncode("My message"))
client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0")
Dim receivedStream As Stream = client.OpenRead(baseUrl)
Dim reader As StreamReader = new StreamReader(receivedStream)
Dim result As String = reader.ReadToEnd()
receivedStream.Close()
reader.Close()
return result

Perl Send SMS using HTTP GET

use strict;
use LWP::Simple;
use LWP::UserAgent;
use URI::Escape;
use Getopt::Long;
use HTTP::Request::Common;
my %args;
GetOptions(
'help' => $args{help},
'smseagleip=s' => $args{smseagleip},
'user=s' => $args{user},
'password=s' => $args{password},
'dstnum=s' => $args{dstnum},
'msg=s' => $args{msg}
);
if(defined($args{help}) || !defined($args{smseagleip}) || !defined($args{user}) || !defined($args{password}) || !defined($args{dstnum}) || !defined($args{msg}) ) {
print "Usage: script_name.pl --smseagleip --user --password --dstnum --msg n";
exit(0);
}
my $text = uri_escape($args{msg});
my $baseurl = "http://".$args{smseagleip}.'/index.php/http_api/';
my $req = GET $baseurl."send_sms?login=$args{user}&pass=$args{password}&to=$args{dstnum}&message=$text";
my $ua = LWP::UserAgent->new();
my $rsp = $ua->request($req);
if($rsp->content == "OK") {
print "Message sent succesfully to $args{dstnum}n";
} else {
print "Sent failure: " . $rsp->content . "n";
}

Powershell Send SMS using HTTP GET

param(
[string]$to = $(throw "Script usage: sendsms.ps1 -to -message "),
[string]$message = $(throw "Script usage: sendsms.ps1 -to -message ")
)
Add-Type -AssemblyName System.Web
$smseagleip = "192.168.0.101"
$username = "john"
$password = "doe"
$smstext = [System.Web.HttpUtility]::UrlEncode($message)
$url = "http://$smseagleip/index.php/http_api/send_sms?login=$username&pass=$password&to=$to&message=$smstext"
$client = New-Object system.Net.WebClient
$result = $client.downloadString($url)
Write-Host $result

Powershell Send SMS using JSON-RPC

$smseagleUrl='http://192.168.1.101/index.php/jsonrpc/sms'
$smseagleLogin='john'
$smseaglePass='doe'
$msgReceiver='123456789'
$msgText='Message test'
$header = @{"Content-Type"="text/plain"}

$jsonBody=@{method="sms.send_sms";params=@{login=$smseagleLogin;pass=$smseaglePass;to=$msgReceiver;message=$msgText}} | ConvertTo-Json -Compress

Invoke-RestMethod -Uri $smseagleUrl -Headers $header -Body $jsonBody -Method Post

CURL Send SMS using HTTP GET

curl -G --data-urlencode "to=+48123456789" --data-urlencode "message=my message" "http://smseagleip/index.php/http_api/send_sms?login=john&pass=doe"

CURL Send SMS using JSON-RPC

curl -H "Content-Type: application/json" -X POST -d '{"method":"sms.send_sms", "params":{"login":"john","pass":"doe","to":"+48123456789","message":"My message"}}' http://smseagleip/index.php/jsonrpc/sms

C++ Send SMS using HTTP GET

#include <iostream>
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
  CURL *curl;
  CURLcode res;
  using namespace std;

  curl = curl_easy_init();
  if(curl) {

    //prepare URL with parameters   
    string path = "http://smseagleip/index.php/http_api/send_sms?login=john&pass=doe";

    char *receipent = curl_easy_escape(curl, "+4812345678", 0);
    char *message = curl_easy_escape(curl, "my message", 0);

    string url;

    url += path;
    url += "&to=";
    url += receipent;
    url += "&message=";
    url += message;

    char * urlchar = new char[url.size() + 1];
    std::copy(url.begin(), url.end(), urlchar);
    urlchar[url.size()] = '\0'; 

    curl_easy_setopt(curl, CURLOPT_URL, urlchar);

    //send HTTP GET request
    res = curl_easy_perform(curl);

    //check for errors
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    curl_easy_cleanup(curl);
  }
 return 0;
}

Other languages

You can also use Ruby, C/C++, VBScript, or other programming/scripting language of your choice. Just use the tools you know best. How to to it? Create a webclient and call HTTP GET as described above. In response you will get OK or ERROR message.