SMS from Perl using HTTP request

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

thomasqueen

Thread Starter
Joined
Jan 23, 2013
Messages
1
[FONT=&quot]Hey guys. For my project, I needed to find a way to send SMS messages from Perl.[/FONT] It turns out, it is easy to send messages from Perl using HTTP requestes and a software called Ozeki NG SMS Gateway.
[FONT=&quot]To send SMS messages from Perl using HTTP requests, first you need to download, [/FONT][FONT=&quot]install and configure Ozeki NG SMS Gateway software[/FONT][FONT=&quot] to your computer. Then import the source code provided below into a new project you write in Perl. After you imported it you can configure the code. You need to customize the values in the source code below. [/FONT]
[FONT=&quot] #!/usr/bin/perl[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]
## Ozeki NG - SMS Gateway Perl example ##[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
use HTTP::Request;[/FONT]
[FONT=&quot]
use LWP::UserAgent;[/FONT]
[FONT=&quot]
use URI::Escape;[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]
### Ozeki NG informations ###[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]
$host = "127.0.0.1";[/FONT]
[FONT=&quot]
$port = "9501";[/FONT]
[FONT=&quot]
$username = "admin";[/FONT]
[FONT=&quot]
$password = "abc123";[/FONT]
[FONT=&quot]
$recipient = "+00123456";[/FONT]
[FONT=&quot]
$message = "Test Message from Perl";[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]
### Putting together the final HTTP Request ###[/FONT]
[FONT=&quot]
###############################################[/FONT]
[FONT=&quot]
$url = "http://" . $host;[/FONT]
[FONT=&quot]
$url .= ":" . $port;[/FONT]
[FONT=&quot]
$url .= "/api?action=sendmessage&";[/FONT]
[FONT=&quot]
$url .= "username=" . uri_escape($username);[/FONT]
[FONT=&quot]
$url .= "&password=" . uri_escape($password);[/FONT]
[FONT=&quot]
$url .= "&recipient=" . uri_escape($recipient);[/FONT]
[FONT=&quot]
$url .= "&messagetype=SMS:TEXT";[/FONT]
[FONT=&quot]
$url .= "&messagedata=" . uri_escape("HELLO WORLD");[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
################################################[/FONT]
[FONT=&quot]
#### Sending the message ###[/FONT]
[FONT=&quot]
################################################[/FONT]
[FONT=&quot]
$request = HTTP::Request->new(GET=>$url);[/FONT]
[FONT=&quot]
$useragent = LWP::UserAgent->new;[/FONT]
[FONT=&quot]
$response = $useragent->request($request);[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]

[/FONT]
[FONT=&quot]
################################################[/FONT]
[FONT=&quot]
### Verifying the response ###[/FONT]
[FONT=&quot]
################################################[/FONT]
[FONT=&quot]
if ($response->is_success) {[/FONT]
[FONT=&quot]
print "Message successfully sent"[/FONT]
[FONT=&quot]
} else {[/FONT]
[FONT=&quot]
print "Message not sent! Please check your settings!"[/FONT]
[FONT=&quot]
}[/FONT]

What do you think? Thomas
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top