-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendSms.java
More file actions
48 lines (41 loc) · 1.43 KB
/
Copy pathSendSms.java
File metadata and controls
48 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package spreadsheet;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class SendSms {
public static String API_KEY="fQD2D47X2j8-wLGjIoR18xaojKqjhLU7PgC4mWvL3b";
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public static String sendSms(String phno) {
try {
// Construct data
String apiKey = "apikey=" + API_KEY;
String message = "&message=" + "This is the message from subash";
String sender = "&sender=" + "TXTLCL";
String numbers = "&numbers=" +phno;
// Send data
HttpURLConnection conn = (HttpURLConnection) new URL("https://api.textlocal.in/send/?").openConnection();
String data = apiKey + numbers + 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;
}
}
}