Explore our Tutorials, Code Samples, SDKs and other resources to help you start building with EgoSms.
Developer Documentation
Sending SMS
Balance Inquiry
Transaction Status
Middleware
Data Conversions to JSON
PLAIN TEXT
XML
package trial;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
public class textConvert {
public static void main(String[] args) {
try
{
// URL for the API content
URL url = new URL("https://demo20.pahappademo.net/middleware/plaintexttojson.php");
// Create an HTTPURL Conncetion
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/text");
connection.setDoOutput(true);
// Plain Text data to send
String txtData = "method = sendsms\r\n"
"userdata = username:john,password:123\r\n"
"msgdata = number:0868987654,message:hi,senderid:ego";
// Send text data
try(OutputStream os = connection.getOutputStream())
{
byte[] input = txtData.getBytes("utf-8");
os.write(input, 0, input.length);
}
// GET THE RESPONSE
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
// READ THE RESPONSE
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null)
{
response.append(inputLine);
}
// JSON response
String jsonResponse = response.toString();
System.out.println("JSON Response: " + jsonResponse);
}
}
else
{
System.out.println("Request failed with response code :" + responseCode);
}
}
catch (Exception e)
{
}
}
}
package trial;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
public class XmlConvert {
public static void main(String[] args) {
try
{
// URL for the API content
URL url = new URL("https://demo20.pahappademo.net/middleware/xml_msg.php");
// Create an HTTPURL Conncetion
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/xml");
connection.setDoOutput(true);
// XML data to send
String xmlData = "\r\n"
+ " SendSms \r\n"
+ " \r\n"
+ " Egotest \r\n"
+ " xxxxx \r\n"
+ " \r\n"
+ " \r\n"
+ " 256788200915 \r\n"
+ " welcome to Egosms \r\n"
+ " Egosms \r\n"
+ " \r\n"
+ " ";
// Send XML data
try(OutputStream os = connection.getOutputStream())
{
byte[] input = xmlData.getBytes("utf-8");
os.write(input, 0, input.length);
}
// GET THE RESPONSE
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
// READ THE RESPONSE
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())))
{
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null)
{
response.append(inputLine);
}
// JSON response
String jsonResponse = response.toString();
System.out.println("JSON Response: " + jsonResponse);
}
}
else
{
System.out.println("Request failed with response code :" + responseCode);
}
}
catch (Exception e)
{
}
}
}