Power of PYTHON and RUBY languages


Hi friends,

Since last week i had worked with Send SMS via rails application. After long search, i found a site called “freesmsapi.com” which provides API and sends SMS. This site  is very much helpful in sending automated SMS.

They also provide  codes for different languages like “Python, Ruby, PHP, Perl, Java, C, C#, VB.NET”

When i compared the same code for different languages, I was surprised (shocked😛 )to see that PYTHON and RUBY has the minimal and very efficient code.🙂

RUBY:

require 'net/http'
require 'uri'
Net::HTTP.get_print URI.parse('<a href="http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER">http://s1.freesmsapi.com/messages/send?skey=8c0185641435ac8a43cf10230a1417ac&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER</a>')

PYTHON:

from urllib
import urlopen
print urlopen('http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER').read()

Here are the codes for other languages.

PHP:


echo file_get_contents("http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=".urlencode('YOUR MESSAGE')."&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBERS");

PERL:

use strict;

use LWP::UserAgent;

my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $url='http://s1.freesmsapi.com/messages/send?skey=89600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER';
my $request = new HTTP::Request('GET', $url);
my $response = $ua->request($request);
my $content = $response->content();
print $content;

JAVA:

import java.net.*;
import java.io.*;

public class JavaGetUrl {
public static void main(String[] args) throws Exception {
URL myurl = new URL("http://s1.freesmsapi.com/messages/send?skey=89600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER");
BufferedReader in = new BufferedReader(
new InputStreamReader(
myurl.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();
}
}

C:

#include <curl/curl.h>

void main() {

long http_code = 0;
CURL *curl;
CURLcode res;

//Initializing the CURL module
curl = curl_easy_init();

if(curl) {

curl_easy_setopt(curl, CURLOPT_URL, "http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER");
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#:

using System.IO;
using System.Net;
string connectionString = "http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER";
try
{
System.IO.Stream SourceStream = null;
System.Net.HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(connectionString);
myRequest.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse webResponse = (HttpWebResponse)myRequest.GetResponse();
SourceStream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(webResponse.GetResponseStream());
string str = reader.ReadLine();
MessageBox.Show(str);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
VB.NET:
Imports System.IO
Imports System.Net
Dim connectionString As String = "http://s1.freesmsapi.com/messages/send?skey=9600152989passwd&message=YOUR_MESSAGE&senderid=YOUR_SENDERID&recipient=MOBILE_NUMBER"
Try
Dim SourceStream As System.IO.Stream
Dim myRequest As System.Net.HttpWebRequest = WebRequest.Create(connectionString)
myRequest.Credentials = CredentialCache.DefaultCredentials
Dim webResponse As WebResponse = myRequest.GetResponse
SourceStream = webResponse.GetResponseStream()
Dim reader As StreamReader = New StreamReader(webResponse.GetResponseStream())
Dim str As String = reader.ReadLine()
MessageBox.Show(str)

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

     

2 thoughts on “Power of PYTHON and RUBY languages

  1. Good stuff…

    But all the above codes are working code or we have to fill up the SENDERID, YOUR MESSAGE, MOBILE NUMBER ?????

    Can you give us the working code for sample…
    Send me some msg to my no, 07827990988… If that is good service means I will buy a domain for us, and we will write small script to send One Day One Command through this instead of sending from sim card …..

    Please post it clearly the working code to send free sms…

    Thanks. …

    • code:
      require ‘net/http’
      require ‘uri’
      Net::HTTP.get_print URI.parse(‘http://s1.freesmsapi.com/messages/send?skey=8c01856435ac8a43cf10230a1417ac&message=Hi+this+is+example+code&senderidsh&recipient=9600152989’)

      But this is not good site to send OAOD. Because this site blocks DND Numbers.😦

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s