Lenguaje "C"
Enviar mensajes – REST API – JSON
CURL *hnd = curl_easy_init();
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://api.labsmobile.com/json/send");
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");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"message\":\"Text of the SMS message\", \"tpoa\":\"Sender\",\"recipient\":[{\"msisdn\":\"12015550123\"},{\"msisdn\":\"447400123456\"},{\"msisdn\":\"5212221234567\"}]}");
CURLcode ret = curl_easy_perform(hnd);
[/c]
Consulta de créditos – REST API – JSON
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);
[/c]
Enviar mensajes – HTTP/GET
|
1
2
3
4
5
6
7
8
9
10
11
|
<br />CURL *hnd = curl_easy_init();</p><p>curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");<br />curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);<br />curl_easy_setopt(hnd, CURLOPT_USERNAME, "myusername");<br />curl_easy_setopt(hnd, CURLOPT_PASSWORD, "mypassword");</p><p>struct curl_slist *headers = NULL;<br />headers = curl_slist_append(headers, "Cache-Control: no-cache");<br />curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);</p><p>CURLcode ret = curl_easy_perform(hnd);<br /> |
Consulta de créditos – HTTP/GET
void main() {
long http_code = 0;
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl,CURLOPT_URL, "http://api.labsmobile.com/get/balance.php?username=[X]&password=[X]");
res = curl_easy_perform(curl);
if(CURLE_OK == res) {
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if(http_code == 200) {
puts("Received 200 status code");
} else {
puts("Did not received 200 status code");
}
}
} else {
puts("Could not initialize curl");
}
}
[/c]