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

Hi fellow monks.

I am working on a script that is supposed to send an SMS through www.mtnsms.com (free SMS service). I think i have figured out how there forms work and witch parameters to send. But the thing is that they use cookies to indentify the user and the post method to send the info to the scripts. So now my question is this:

How do I send the post info and cookies to the server?
Is there any modules that I can use for this type of things?

// Martin

Replies are listed 'Best First'.
Re: Sending Post Forms and Cookies
by Corion (Patriarch) on Oct 27, 2000 at 15:26 UTC

    I assume that you are using LWP::UserAgent to do the server communication. If you're not doing this, think about doing this. The only drawback of LWP::UserAgent is, that it is not in the Perl distribution, but we have may documents in the monastery detailing how to install modules (even if you don't have administrative privileges) - use the Super Search and search for module and install or something like that.

    If you're using LWP::UserAgent, there is the module HTTP::Cookies and the method $agent->cookie_jar() of your useragent. Just get the cookie jar from the useragent, fill it with the right cookie(s), and that would be it.

    As an additional extra, you get proxy support for free with LWP::UserAgent.

    Here's some untested code to manipulate cookies of UserAgent :

    use strict; use LWP::UserAgent; use vars qw($ua, $request, $response, $cookie_jar, $URL); $ua = new LWP::UserAgent; # Read proxy settings from the environment, if given $ua->proxy(); $request = new HTTP::Request($URL); $response = $ua->request( $request ); $cookie_jar = new HTTP::Cookies; $cookie_jar->extract_cookies($response); # Tell $ua to use our cookie jar : $ua->cookie_jar($cookie_jar); # Make our cookies persistent $cookie_jar->save("cookie_jar"); $ua->cookie_jar($cookie_jar);
Re: Sending Post Forms and Cookies
by AgentM (Curate) on Oct 27, 2000 at 18:52 UTC
    Wow. You know I performed a quick search at freshmeat and oddly enough the first match was perfect: "mtsms.pl is a Perl script that can send sms messages non-interactively through the mtnsms.com web service." You might want to take a look at it since it's exactly what you want to do- except done and working.
    AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.
clearifying my post
by Martin A (Beadle) on Oct 27, 2000 at 17:51 UTC
    Ok, I read the reply i got and my question again and i think the question wasn't really clear. so here comes a try to fix that.

    What I want to do is to make the script to act as a client (like Netscape) and request a page (in this case a output from a script) and in that request send som enviroment vars like HTTP_COOKIE and HTTP_REFERER (i think thats what they are called) etc, and form info (method post).

    Hope this makes the question a bit clearer.

    // Martin
      The example given in the node above yours did mostly that. Set $URL to the URL that sets the cookie, and the LWP stuff will request it via a user agent of its own, noting the cookies and saving them for future reference. Follow up that example code with code that actually posts your form.

      See the documentation for the LWP::UserAgent and, say, HTTP::Request stuff.. examples are extensive.