textlocal java api

Solutions on MaxInterview for textlocal java api by the best coders in the world

showing results for - "textlocal java api"
Elías
29 Sep 2017
1import java.io.BufferedReader;
2import java.io.InputStreamReader;
3import java.io.OutputStreamWriter;
4import java.net.URL;
5import java.net.URLConnection;
6import java.net.URLEncoder;
7
8public class sendSMS {
9	public String sendSms() {
10		try {
11			// Construct data
12			String apiKey = "apikey=" + "yourapiKey";
13			String message = "&message=" + "This is your message";
14			String sender = "&sender=" + "Jims Autos";
15			String numbers = "&numbers=" + "447123456789";
16
17			// Send data
18			HttpURLConnection conn = (HttpURLConnection) new URL("https://api.txtlocal.com/send/?").openConnection();
19			String data = apiKey + numbers + message + sender;
20			conn.setDoOutput(true);
21			conn.setRequestMethod("POST");
22			conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
23			conn.getOutputStream().write(data.getBytes("UTF-8"));
24			final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
25			final StringBuffer stringBuffer = new StringBuffer();
26			String line;
27			while ((line = rd.readLine()) != null) {
28				stringBuffer.append(line);
29			}
30			rd.close();
31
32			return stringBuffer.toString();
33		} catch (Exception e) {
34			System.out.println("Error SMS "+e);
35			return "Error "+e;
36		}
37	}
38}
similar questions
queries leading to this page
textlocal java api