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

As posted on the chatterbox peewee_zz: Hello. I'm brand new, and little more than a novice when it comes to PERL... I normally would just stick to the MB but it suggested here first. I'm having problems with cURL. Before I eloborate are there any FAQ's I should check out first?
peewee_zz: Basically I have curl in /usr/bin/curl but I do not have the www::curl object from CPAN installed. Is there a way to use the existing file, and if not how do I isntall the CPAN object even though I am not using Active PERL

I am creating a .cgi on a linux server. I do not know what flavor or version of linux because I am telnet-ing in to program it. I DO NOT have active perl installed and the CPAN command is an unrecognized command. I also am a rather novice PERL programmer so code snipits are the best bet for help.

Replies are listed 'Best First'.
Re: Using CURL
by Asim (Hermit) on May 05, 2006 at 14:51 UTC
    I do not know what flavor or version of linux because I am telnet-ing in to program it.

    That's not a problem for many versions of UNIX and UNIX-like OSes. Once you login, simply type uname -a and hit ENTER, and it'll usually give some quasi-cryptic text that'll tell the tale of what OS and version it's running.

    I am creating a .cgi on a linux server.

    Understood; a lot of us on here use that setup. Rather than dance around the questions, may I second marto's comment? May we ask you, instead, to give us a detailed description of what you're trying to do, what your goal is, what this CGI application should do when it runs? That way, we might be able to point you to an answer that may or may not involve cURL, but might be easier to explain and implement for you, as well as "safer" for you to put on the web, which is a critical point these days.

    I know it sounds like a lot of work + "the runaround", but experience shows that sometimes the best answers come from thinking "outside the box". :)

    ----Asim, known to some as Woodrow.

      Well that was the comment I was looking for:

      -bash-3.00$ uname -a Linux ns1.netwire-solutions.com 2.6.9-5.EL #1 Wed Jan 5 19:22:18 EST 2005 i686 i686 i386 GNU/Linux

      I'm developing a sign up form for a paid membership. After the program takes the desired user information, it will then give the form for the payment information. To connect to the API I need to send XML formated information to the API. It suggests using cURL but gives no sample code on using it. It does describe a sample module that they are supposed to provide, but this merchant account is going through support changes and I can't find support for that other module.

      I'm thinking that if security is a big concern with cURL then I should focus more time on installing the other module.

      The program only needs to send a single price for a single item from a single person to a seperate API that then handles everything else. I would like to get cURL working before switching to a more secure form of transfering just for my own personal experience... That being said what was the prerequisite again for WWW::CURL

        I need to send XML formated information to the API.

        So there's money involved, hmmm? That's going to make it interesting. It's a simple problem, in theory; I concur with others that using LWP is going to be a big win over calling cURL; it may seem simpler at the beginning, but the potential for a muck-up is higher. I suspect they use cURL as an example because you'll find it on most platforms, and the concepts are universal to any HTTP client/server setup.

        I see someone has given an example already, go you! So I'm deleting mine, but also pointing you to the LWP Cookbook for examples, and I'll keep this "assumptions to watch for" bit, which include:

        1. You know the URL to send the XML data to,
        2. You either have pre-generated XML payment data, or know how to create it,
        3. You realize that cURL, LWP, etc. do not format or create the XML, they only send the raw data,
        4. You either know or can find out if they are using a different content-type header than the standard.

        In short -- this is a good bit of work. And that's before the security stuff...

        if security is a big concern with cURL then I should focus more time on installing the other module.

        It's not cURL that's the security problem, per se. Any data you pick up from a user and do anything with can be a problem down the road. One example is our old friend SQL Injection, another is someone sending backticked data to a program on the command line. "Backtick", FYI, is one of the ways you can call a program via Perl with something like `/usr/bin/curl http://www.payment_center.com`.

        But it is so not recommended. If a bad person tries hard enough, they can likely break your system with the right code, since you're sending text to the command line under your login. Beyond that, checking for errors is tough, and you need to do that, otherwise how do you tell people if their payment goes through, or figure out if the payment center's system is up or down? It's not impossible...but it's much easier in LWP, overall.

        Does any of this help? What might also be of aid is to read up on CGI and Perl; Ovid's CGI Course is a good place to start.

        ----Asim, known to some as Woodrow.

        WWW::Curl has an awful programming interface. Use libwww-perl instead. Here an example of how complicated it can get at the most: making a HTTP POST request with a custom HTTP header field and XML in the HTTP message body.
        #!/usr/bin/perl -T use strict; use diagnostics; use LWP::UserAgent; my $req = HTTP::Request->new( POST => 'http://example.com/webservice', # method and URI ); $req->content_type('application/xml'); $req->content('<hello>world!</hello>'); my $ua = LWP::UserAgent->new; $ua->timeout(5); my $res = $ua->request($req); print $res->content if $res->is_success;
Re: Using CURL
by marto (Cardinal) on May 05, 2006 at 14:37 UTC
Re: Using CURL
by zentara (Cardinal) on May 05, 2006 at 16:19 UTC
    I agree with Anonymous Monk, that Curl is very hard to use, and a beginner would be happier with LWP. Curl has so many options that need to be manually set for it to work right. The question I have is "what are you trying to do with curl"?

    For some simple operations with curl, you can run /usr/bin/curl (with options) with a system, or fork-and-exec.


    I'm not really a human, but I play one on earth. flash japh
Re: Using CURL
by dorward (Curate) on May 05, 2006 at 14:38 UTC