Lenguaje "Java"

Enviar mensajes – REST API – JSON

[java]
HttpResponse response = Unirest.post("https://api.labsmobile.com/json/send")
  .header("Content-Type", "application/json")
  .basicAuth("myusername","mypassword")
  .header("Cache-Control", "no-cache")
  .body("{\"message\":\"Text of the SMS message\", \"tpoa\":\"Sender\",\"recipient\":[{\"msisdn\":\"12015550123\"},{\"msisdn\":\"447400123456\"},{\"msisdn\":\"5212221234567\"}]}")
  .asString();
[/java]

Consulta de créditos – REST API – JSON

1
2
3
4
5
6
7
8
9
10
11
12
13
CURL *hnd = curl_easy_init();
 
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.labsmobile.com/json/balance");
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);
curl_easy_setopt(hnd, CURLOPT_USERNAME, "myusername");
curl_easy_setopt(hnd, CURLOPT_PASSWORD, "mypassword");
 
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Cache-Control: no-cache");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
 
CURLcode ret = curl_easy_perform(hnd);

Enviar mensajes – HTTP/GET

[java]
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

...

HttpURLConnectionExample http = new HttpURLConnectionExample();

String url = "http://api.labsmobile.com/get/send.php?username=[X]&password=[X]&msisdn=34609036253&sender=SENDER&message=This+is+the+message";

URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
int responseCode = con.getResponseCode();

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
	response.append(inputLine);
}
in.close();
System.out.println(response.toString());
[/java]

Consulta de créditos – HTTP/GET

[java]
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

...

HttpURLConnectionExample http = new HttpURLConnectionExample();

String url = "http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]";

URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
int responseCode = con.getResponseCode();

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
	response.append(inputLine);
}
in.close();
System.out.println(response.toString());
[/java]

Llámanos