Java SMS API Integration Code
Use this Java implementation using HttpURLConnection to send SMS messages via HighSpeedSMS HTTP gateway. You can easily adapt it into any Java servlet, Spring Boot application, or Android backend service.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Properties;
public class CallSmscApi {
public CallSmscApi() {
}
/*
* 1. Create a URL.
* 2. Retrieve the URLConnection object.
* 3. Set output capability on the URLConnection.
* 4. Open a connection to the resource.
* 5. Get an output stream from the connection.
* 6. Write to the output stream.
* 7. Close the output stream.
*/
public static void main(String[] args) throws Exception {
String postData = "";
String retval = "";
// API parameters
String User = "User_Name";
String passwd = "Password";
String mobilenumber = "919XXXXXXXXX"; // Comma-separated for bulk
String message = "Your SMS Message here";
String sid = "Sender_Id";
String mtype = "N"; // N for Normal, U for Unicode
String DR = "Y"; // Y for Delivery Report
postData += "User=" + URLEncoder.encode(User, "UTF-8")
+ "&passwd=" + passwd
+ "&mobilenumber=" + mobilenumber
+ "&message=" + URLEncoder.encode(message, "UTF-8")
+ "&sid=" + sid
+ "&mtype=" + mtype
+ "&DR=" + DR;
URL url = new URL("http://smscountry.com/SMSCwebservice_Bulk.aspx");
HttpURLConnection urlconnection = (HttpURLConnection) url.openConnection();
// Optional: If behind a proxy server, uncomment below:
// Properties sysProps = System.getProperties();
// sysProps.put("proxySet", "true");
// sysProps.put("proxyHost", "Proxy_IP");
// sysProps.put("proxyPort", "Proxy_Port");
urlconnection.setRequestMethod("POST");
urlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlconnection.setDoOutput(true);
OutputStreamWriter out = new OutputStreamWriter(urlconnection.getOutputStream());
out.write(postData);
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(urlconnection.getInputStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
retval += decodedString;
}
in.close();
System.out.println("API Response: " + retval);
}
}












