Message-ID: <1973112351.15675.1614957504406.JavaMail.confluence@wiki> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_15674_867862475.1614957504405" ------=_Part_15674_867862475.1614957504405 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Get started instantly. You can = copy & paste the code examples below for use with our SMS API Gateway.<= /span>
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; // Simple send SMS programm public class SendSMS { public static String sendSMS(String username, String password, String t= o, String message, String originator) { String url; StringBuilder inBuffer =3D new StringBuilder(); try { url =3D "http://api.textmarketer.co.uk/gateway/" + "?username=3D" + username + "&password= =3D" + password + "&option=3Dxml" + "&to=3D" + to + "&message=3D" += URLEncoder.encode(message, "UTF-8") + "&orig=3D" + URLEncoder.encode(originator, &q= uot;UTF-8"); } catch (UnsupportedEncodingException e) { return null; } try { URL tmUrl =3D new URL(url); URLConnection tmConnection =3D tmUrl.openConnection(); tmConnection.setDoInput(true); BufferedReader in =3D new BufferedReader(new InputStreamReader(= tmConnection.getInputStream())); String inputLine; while ((inputLine =3D in.readLine()) !=3D null) inBuffer.append(inputLine); in.close(); } catch (IOException e) { return null; } return inBuffer.toString(); } public static void main(String[] args) { // Example of use=20 String response =3D sendSMS("myUsername", "myPasswor= d", "4477777777", "My test message", "TextMes= sage"); System.out.println(response); } }=20
=20
<?php // Simple SMS send function function sendSMS($username, $password, $to, $message, $originator) { $URL =3D 'http://api.textmarketer.co.uk/gateway/'."?username= =3D$username&password=3D$password&option=3Dxml"; $URL .=3D "&to=3D$to&message=3D".urlencode($messa= ge).'&orig=3D'.urlencode($originator); $fp =3D fopen($URL, 'r'); return fread($fp, 1024); } // Example of use=20 $response =3D sendSMS('myUsername', 'myPassword', '4477777777', 'My tes= t message', 'TextMessage'); echo $response;?>=20
using System; using System.IO; using System.Net; using System.Text; using System.Web; namespace SendSMS { class Program { public static string SendSMS(string username, string password, stri= ng to, string message, string originator) { StringBuilder sb =3D new StringBuilder(); byte[] buf =3D new byte[1024]; string url =3D "http://api.textmarketer.co.uk/gateway/&quo= t; + "?username=3D" + username + "&password= =3D" + password + "&option=3Dxml" + "&to=3D" + to + "&message=3D" += HttpUtility.UrlEncode(message) + "&orig=3D" + HttpUtility.UrlEncode(originator= ); HttpWebRequest request =3D (HttpWebRequest)WebRequest.Create(ur= l); HttpWebResponse response =3D (HttpWebResponse)request.GetRespon= se(); Stream resStream =3D response.GetResponseStream(); string tempString =3D null; int count =3D 0; do { count =3D resStream.Read(buf, 0, buf.Length); if (count !=3D 0) { tempString =3D Encoding.ASCII.GetString(buf, 0, count); sb.Append(tempString); } } while (count > 0); return sb.ToString(); } static void Main(string[] args) { string respXML =3D SendSMS("myUsername", "myPass= word", "4477777777", "My test message", "Text= Message"); Console.WriteLine(respXML); } } }=20
#include <iostream> #include <string> #using <System.Dll> #using <System.Web.Dll> using namespace std; using namespace System; using namespace System::Web; using namespace System::Net; using namespace System::IO; using namespace System::Runtime::InteropServices; ref class SMSSender { private: static String^ Username =3D "myUsername"; static String^ Password =3D "myPassword"; public: SMSSender() {} String^ SendSMS(String^ To, String^ Message, String^ From) { Message =3D HttpUtility::UrlEncode(Message); From =3D HttpUtility::UrlEncode(From); String^ URL =3D "http://api.textmarketer.co.uk/gateway= /?&option=3Dxml&username=3D" + Username + "&password= =3D" + Password + "&message=3D" + Message + "&o= rig=3D" + From + "&to=3D" + To; WebRequest^ Handle =3D WebRequest::Create(URL); WebResponse^ HTTPResponse =3D Handle->GetResponse(); StreamReader^ Stream =3D gcnew StreamReader(HTTPResponse-&g= t;GetResponseStream()); String^ Response =3D Stream->ReadToEnd()->Trim(); HTTPResponse->Close(); return Response; } }; int main() { SMSSender^ test =3D gcnew SMSSender(); String^ resp =3D test->SendSMS("4477777777", "My = test message", "TextMessage"); Console::WriteLine(resp); return 0; }=20
/* * Send SMS C/C++ example need curllib download from http://curl.hax= x.se/ */ #include <stdio.h> #include <tchar.h> #include <string.h> #include <curl/curl.h> #define URLSIZE 256 struct MemoryStruct { char *memory; size_t size; }; /* Converts a hex character to its integer value */ char from_hex(char ch) { return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; } /* Converts an integer value to its hex character*/ char to_hex(char code) { static char hex[] =3D "0123456789abcdef"; return hex[code & 15]; } /* Returns a url-encoded version of str */ char *url_encode(char *str) { char *pstr =3D str, *buf =3D (char *)malloc(strlen(str) * 3 + 1), *= pbuf =3D buf; while (*pstr) { if (isalnum(*pstr) || *pstr =3D=3D '-' || *pstr =3D=3D '_' = || *pstr =3D=3D '.' || *pstr =3D=3D '~') *pbuf++ =3D *pstr; else if (*pstr =3D=3D ' ') *pbuf++ =3D '+'; else *pbuf++ =3D '%', *pbuf++ =3D to_hex(*pstr >> = 4), *pbuf++ =3D to_hex(*pstr & 15); pstr++; } *pbuf =3D '\0'; return buf; } /* CURL Callback write function */ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb= , void *userp) { size_t realsize =3D size * nmemb; struct MemoryStruct *mem =3D (struct MemoryStruct *)userp; mem->memory =3D (char *)realloc(mem->memory, mem->size + r= ealsize + 1); if (mem->memory =3D=3D NULL) { /* out of memory! */ printf("not enough memory (realloc returned NULL)\n&qu= ot;); exit(EXIT_FAILURE); } memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size +=3D realsize; mem->memory[mem->size] =3D 0; return realsize; } /* Send SMS */ char * sendSMS(const char *username, const char *password, const char *to, = char *message, char *originator) { static char url[URLSIZE] =3D "http://api.textmarketer.co.uk/ga= teway/?option=3Dxml"; char *encoded; CURL *curl; CURLcode res; struct MemoryStruct chunk; chunk.memory =3D (char *)malloc(1); /* will be grown as needed by = the realloc above */ chunk.size =3D 0; /* no data at this point */ curl =3D curl_easy_init(); if(curl) { strcat_s(url, URLSIZE, "&username=3D"); strcat_s(url, URLSIZE, username); strcat_s(url, URLSIZE, "&password=3D"); strcat_s(url, URLSIZE, password); strcat_s(url, URLSIZE, "&to=3D"); strcat_s(url, URLSIZE, to); strcat_s(url, URLSIZE, "&message=3D"); encoded =3D url_encode(message); strcat_s(url, URLSIZE, encoded); free(encoded); encoded =3D url_encode(originator); strcat_s(url, URLSIZE, "&orig=3D"); strcat_s(url, URLSIZE, encoded); free(encoded); curl_easy_setopt(curl, CURLOPT_URL, url); /* send all data to this function */ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCa= llback); /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chun= k); if((res =3D curl_easy_perform(curl)) !=3D CURLE_OK) { return NULL; } curl_easy_cleanup(curl); } return chunk.memory; } int main(void) { char *response; response =3D sendSMS("myuser", "mypass", "= 4477777777", "test test test", "me"); if(response !=3D NULL) { printf(response); free(response); } getchar(); return 0; }=20
Imports System.Web Module Module1 Public Function SendSMS(ByVal username As String, ByVal password As Str= ing, ByVal toPhone As String, ByVal message As String, ByVal originator As St= ring) Dim webClient As New System.Net.WebClient Dim url As String =3D "http://api.textmarketer.co.uk/gateway/?= username=3D" & username & "&password=3D" & password = & "&option=3Dxml" & "&to=3D" & toPhone & "&messa= ge=3D" & System.Web.HttpUtility.UrlEncode(message) & "&orig=3D" & System.Web.HttpUtility.urlen= code(originator) Dim result As String =3D webClient.DownloadString(url) SendSMS =3D result End Function Sub Main() Dim result As String =3D SendSMS("myUsername", "myPa= ssword", "4477777777", "My test message", "Te= xtMessage") Console.WriteLine(result) Console.ReadKey() End Sub End Module=20
<%@language=3DJScript%><% username =3D "myUsername"; password =3D "myPassword"; number =3D "4477777777"; message =3D Server.URLEncode("My test message"); originator =3D Server.URLEncode("TextMessage"); url =3D "http://www.textmarketer.biz/gateway/?&option=3Dxml&qu= ot; + "&username=3D" + username + "&password= =3D" + password + "&number=3D" + number + "&message=3D&quo= t; + message + "&orig=3D" + originator; var objSrvHTTP; objSrvHTTP =3D Server.CreateObject("Msxml2.ServerXMLHTTP"); objSrvHTTP.open(url, false); objSrvHTTP.send(); Response.ContentType =3D "text/xml"; xmlResp =3D objSrvHTTP.responseXML.xml; Response.Write(xmlResp);%>=20
require 'net/http' require 'uri' def send_sms(username, password, to, message, originator) requested_url =3D 'http://api.textmarketer.co.uk/gateway/?option=3Dxml' + "&username=3D" + username + "&passwo= rd=3D" + password + "&to=3D" + to + "&message=3D" += URI.escape(message) + "&orig=3D" + URI.escape(originator) url =3D URI.parse(requested_url) full_path =3D (url.query.blank?) ? url.path : "#{url.path}?#{url.que= ry}" the_request =3D Net::HTTP::Get.new(full_path) the_response =3D Net::HTTP.start(url.host, url.port) { |http| http.request(the_request) } raise "Response was not 200, response was #{the_response.code}"= if the_response.code !=3D "200" return the_response.bodyend resp =3D send_sms('myUsername', 'myPassword', '4477777777', 'My test messag= e', 'TextMessage') puts(resp)=20
Our example code is an illustra= tion of how you might integrate with our systems and is not certified for p= roduction environments. You are responsible for testing and QA.