All right then... so I suppose I will write you up a short example of POST-ing to a web server, w/o using modules (except for Socket, but you *really* should have that one)--(and not that you really asked :).

WARNING: this may not be great code. But I think it's got the essentials of what you need to do to write a client that POSTs to a web server and receives a response.

use Socket; # remote hostname and port (80, most likely) my $remote = "www.server.com"; my $port = 80; # the URL you want to POST to my $url = "/cgi-bin/form.pl"; # the content you want to POST # (key value pairs, most likely) my $content = "id=103"; # network stuff--lookup host name and convert # it into a packed IP address suitable for # passing to connect. then get the protocol # data needed by socket (for the "tcp" protocol). my $paddr = sockaddr_in $port, inet_aton $remote; my $proto = getprotobyname('tcp'); # open up a socket on your local machine socket S, &AF_INET, &SOCK_STREAM, $proto or die "Can't open socket: $!"; # connect your local socket to the remote host and port connect S, $paddr or die "Can't connect: $!"; # make your socket unbuffered select((select(S), $|=1)[0]); # print POST line to web server, followed by # Content-Length header--this header is essential # so that the web server knows that content will # be sent along in the body of the request print S "POST $url HTTP/1.0\n"; print S "Content-Length: ", length $content, "\n"; print S "\n"; print S $content, "\n\n"; # you've sent the request, now just read back the # response, headers and all, and print it print while <S>; # close up the socket close S;

In reply to RE: Re: Passing POST parameters by btrott
in thread Passing POST parameters by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.