Docy

Did You Know?

Java Sample Code (GET)

                                        
                                            
                                    import java.io.BufferedReader;
                                    import java.io.InputStreamReader;
                                    import java.io.OutputStreamWriter;
                                    import java.net.URL;
                                    import java.net.URLConnection;
                                    import java.net.URLEncoder;
                                    
                                    public class sendSMS {
                                      public String sendSms() {
                                        try {
                                          // Construct data
                                          String apiKey     = "apikey=" + URLEncoder.encode("yourapiKey", "UTF-8");
                                          String message    = "&message=" + URLEncoder.encode("This is your message", "UTF-8");
                                          String sender     = "&sender=" + URLEncoder.encode("SmartSMS", "UTF-8");
                                          String phone      = "&phone=" + URLEncoder.encode("923186373741,923186373741,923186373741", "UTF-8");
                                    
                                          // Send data
                                          String data = "https://www.echosofts.com/api/sendsms.php?" + apiKey + phone + message + sender;
                                          URL url = new URL(data);
                                          URLConnection conn = url.openConnection();
                                          conn.setDoOutput(true);
                                    
                                          // Get the response
                                          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                                          String line;
                                          String sResult = "";
                                          while ((line = rd.readLine()) != null) {
                                            // Process line...
                                            sResult = sResult + line + " ";
                                          }
                                          rd.close();
                                    
                                          return sResult;
                                        } catch (Exception e) {
                                          System.out.println("Error SMS " + e);
                                          return "Error " + e;
                                        }
                                      }
                                    }                       
                                            
                                        
                                    

JAVA Sample Code (POST)

                                        
                                        

                                        import java.io.BufferedReader;
                                        import java.io.InputStreamReader;
                                        import java.io.OutputStreamWriter;
                                        import java.net.URL;
                                        import java.net.URLConnection;
                                        import java.net.URLEncoder;
                                        
                                        public class sendSMS {
                                          public String sendSms() {
                                            try {
                                              // Construct data
                                              String apiKey  = "apikey=" + "yourapiKey";
                                              String message = "&message=" + "This is your message";
                                              String sender  = "&sender=" + "SmartSMS";
                                              String phone   = "&phone=" + "923186373741,923186373741,923186373741";
                                        
                                              // Send data
                                              HttpURLConnection conn = (HttpURLConnection) new URL("https://www.echosofts.com/api/sendsms.php?").openConnection();
                                              String data = apiKey + phone + message + sender;
                                              conn.setDoOutput(true);
                                              conn.setRequestMethod("POST");
                                              conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
                                              conn.getOutputStream().write(data.getBytes("UTF-8"));
                                              final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                                              final StringBuffer stringBuffer = new StringBuffer();
                                              String line;
                                              while ((line = rd.readLine()) != null) {
                                                stringBuffer.append(line);
                                              }
                                              rd.close();
                                        
                                              return stringBuffer.toString();
                                            } catch (Exception e) {
                                              System.out.println("Error SMS " + e);
                                              return "Error " + e;
                                            }
                                          }
                                        }
                                        
                                        
                                         
                                    
CONTENTS