Using Socket to call a Perl CGI : Socket « Network « Perl

Perl
1. Array
2. CGI
3. Class
4. Data Type
5. Database
6. File
7. GUI
8. Hash
9. Language Basics
10. Network
11. Regular Expression
12. Report
13. Statement
14. String
15. Subroutine
16. System Functions
17. Win32
18. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Perl » Network » Socket 
Using Socket to call a Perl CGI
    

use IO::Socket;

$name = 'Tom';
$email = 'a@a.com';

$string = '?' "name=" . $name . "&" "email=" . $email;
$string =~ tr/ /+/;

$socket = IO::Socket::INET->new

    Proto     => "tcp",
    PeerAddr  => "yourserver.com",
    PeerPort  => 80,
);

$socket->autoflush(1);

print $socket "GET /reg.cgi$string ', 'HTTP/1.0\015\012\015\012";

while ($line = <$socket>) {
    $results .= $line
}

close $socket;
print $results;
if ($results =~ /Thanks for registering./mg) {

    print "Success."

else {

    print "Sorry, there was an error."

}

#File: reg.cgi


#!/usr/local/bin/perl

use CGI;                             

$co = new CGI;                        

print $co->header,                    

$co->start_html(
    -title=>'CGI Example', 
    -author=>'yourName', 
    -meta=>{'keywords'=>'CGI Perl'}, 
    -BGCOLOR=>'white', 
    -LINK=>'red'
);

if ($co->param()) {
    $! = 0;
    open FILEHANDLE, ">>reg.log";
    print FILEHANDLE "Date: " . `date`;
    print FILEHANDLE "Name: " . $co->param('name') "\n";
    print FILEHANDLE "email: " . $co->param('email') "\n";
    close FILEHANDLE;
    unless ($!) {
        print "Success.";
    else {
        print "Sorry, there was an error: $!";
    }
}
print $co->end_html;                  

   
    
    
    
  
Related examples in the same category
1. Time Server with Socket
2. Socket server
3. Perl Modules for Networking with Sockets
4. Open a socket
5. Post query to a CGI
6. Query a Perl CGI
7. Listen to a port
8. Using regular expresion to validate an IP address
9. Child handle and parent handle
10. Daytime client, using symbolic host and service names
11. Add a host, delete a host, add a user, delete a user, ping a host, list processes, list filesystems, lists hosts, and kill a process.
12. A Perl TCP server without the Socket module.
13. A Simple script to update your host/ip with dyndns.org service.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.