import java.io.*;
import java.net.*;
import java.util.*;
/**
* Connection Software SendSMS Java Application 2016
* @author Russell Mazonde
*/
public class SendSMS {

/**
* @param args the command line arguments
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception {
//csoft url 
URL url = new URL("https://www.csoft.co.uk/webservices/http/sendsms");

//create a map that holds parameters for the request
Map<String,Object> params = new LinkedHashMap<>();
params.put("Username", "ANOther.12345");
params.put("PIN", "123456");
params.put("Message", "Hello World");
params.put("SendTo", "447700912345");

//use string builder to create formated url request with encoding
StringBuilder postData = new StringBuilder();
for (Map.Entry<String,Object> param : params.entrySet()) {
if (postData.length() != 0) postData.append('&');
postData.append(URLEncoder.encode(param.getKey(), "UTF-8"));
postData.append('=');
postData.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8"));
}

byte[] postDataBytes = postData.toString().getBytes("UTF-8");

//create url connection 
HttpURLConnection conn = (HttpURLConnection)url.openConnection();

//specify type of request i.e. POST or GET
conn.setRequestMethod("POST");

//specify content type and length
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));

conn.setDoOutput(true);
conn.getOutputStream().write(postDataBytes);

//get result from http request
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));

StringBuilder sb = new StringBuilder();
for (int c; (c = in.read()) >= 0;)
sb.append((char)c);

//display response code
System.out.println(sb.toString());
}

}