http://qs321.pair.com?node_id=186715

flappy has asked for the wisdom of the Perl Monks concerning the following question:

I need to simulate a form post, i.e. exactly what a web browser does when you fill in a form and click the submit button.

I have to use the socket library as I cannot use CGI, LWP or any module like that.

  • Comment on How can i simulate a form post using sockets?

Replies are listed 'Best First'.
Re: How can i simulate a form post using sockets?
by CubicSpline (Friar) on Aug 01, 2002 at 13:22 UTC
    Show us what you have so far. What exactly are you having trouble with? Do you not know the Perl necessary to read/write on sockets? Have you gotten that part, but don't know how to formulate the HTTP request?

    No offense, but this sounds like a homework problem (even though it is the middle of summer!). Folks are much more likely to help if you show us what you've tried so we know where you are.

    Post the code you have so far in Seekers of Perl Wisdom and ask a direct question. Don't just ask us to do it for you.

    Looking forward to helping ..

      Well my program is hundreds of lines code big so I'm not asking anyone to do anything for me - just to help me through this situation that has had me stumped for the past 3-4 days and this is my only resort is to ask someone to help... this is my first time on here and I'm asking a genuine question. I've never had to ask anyone for help before in the past 5 years that I've been programming in PERL. I've never dealt with sockets before so maybe sockets isnt the answer for this question - maybe just a simple HTTP header or something ... anyway I've posted my request in Seekers of Perl Wisdom..
Re: How can i simulate a form post using sockets?
by hnd (Scribe) on Jun 29, 2009 at 21:18 UTC
    i think this might just work... (i will keep my fingers crossed)
    use IO::Socket; use strict; my $socket=new IO::Socket( PeerAddr=>$host, PeerPort=>80, #HTTP Proto=>'tcp', ) or die "cannot create socket\n"; #print the input to the socket print $socket "<your get command here">; #read the input from the socket my $data=<$socket>; print $data; print $socket "<your post command here>"; close $socket
    $host is the IP address of the required host
    the thing is to connect to port 80 and do simple HTTP requests.......
    the print statement prints the request to directly to the socket and then it is directly read from the socket
    you can even loop indefinitely if you want..... giving an terminating condition....