script for http request

Discussion in 'Perl Misc' started by RogerF, Feb 15, 2007.

  1. RogerF

    RogerF Guest

    Hello... don't do alot of perl scripting so I am not well experienced
    with scripting...

    I want to return the values from a simple http request in a perl
    script.

    So for example, if I have a http request on a server such as:

    http://<server>/servlet/inbasket?RDUSER=pfuser&FUNCTION=gettasks

    And the return of the URL is:

    <?xml version="1.0" ?>
    - <INBASKET>
    <USERTASKS userid="" returnmsg="No tasks set up for workflow user
    pfuser" msgtype="Error" />
    </INBASKET>

    I want to take the returnmsg value ("No tasks set up for workflow user
    pfuser") from the request and send it to an email recipient.

    Just looking for the syntax of the Http request and how to get the
    return values

    require HTTP::Request;
    $request = HTTP::Request->new(GET => 'http://<server>/servlet/inbasket?
    RDUSER=pfuser&FUNCTION=gettasks');
    ....
    ....
    ....
    $response = $ua->request($request)
    if ($response->is_success) {
    print $response->content;
    }
    else {
    print STDERR $response->status_line, "\n";
    ********************************************************************

    So how do I get the value of returnmsg??? Can I somehow parse out
    'content'??

    Needing just a little help to get this syntax correct.

    Thanks in advance for your assistance.

    -Roger
     
    RogerF, Feb 15, 2007
    #1
    1. Advertising

  2. RogerF

    J. Gleixner Guest

    RogerF wrote:
    [...]
    > So for example, if I have a http request on a server such as:
    >
    > http://<server>/servlet/inbasket?RDUSER=pfuser&FUNCTION=gettasks
    >
    > And the return of the URL is:
    >
    > <?xml version="1.0" ?>
    > - <INBASKET>
    > <USERTASKS userid="" returnmsg="No tasks set up for workflow user
    > pfuser" msgtype="Error" />
    > </INBASKET>

    [...]
    > So how do I get the value of returnmsg??? Can I somehow parse out
    > 'content'??
    >
    > Needing just a little help to get this syntax correct.
    >
    > Thanks in advance for your assistance.


    It's XML, of course it can be parsed. Take a look at XML::Simple, on
    CPAN (http://search.cpan.org/)
     
    J. Gleixner, Feb 15, 2007
    #2
    1. Advertising

  3. RogerF

    gf Guest

    On Feb 15, 8:39 am, "RogerF" <> wrote:
    > Hello... don't do alot of perl scripting so I am not well experienced
    > with scripting...
    >
    > I want to return the values from a simple http request in a perl
    > script.
    >
    > So for example, if I have a http request on a server such as:
    >
    > http://<server>/servlet/inbasket?RDUSER=pfuser&FUNCTION=gettasks
    >
    > And the return of the URL is:
    >
    > <?xml version="1.0" ?>
    > - <INBASKET>
    > <USERTASKS userid="" returnmsg="No tasks set up for workflow user
    > pfuser" msgtype="Error" />
    > </INBASKET>
    >
    > I want to take the returnmsg value ("No tasks set up for workflow user
    > pfuser") from the request and send it to an email recipient.
    >
    > Just looking for the syntax of the Http request and how to get the
    > return values
    >
    > require HTTP::Request;
    > $request = HTTP::Request->new(GET => 'http://<server>/servlet/inbasket?
    > RDUSER=pfuser&FUNCTION=gettasks');
    > ...
    > ...
    > ...
    > $response = $ua->request($request)
    > if ($response->is_success) {
    > print $response->content;
    > }
    > else {
    > print STDERR $response->status_line, "\n";
    > ********************************************************************


    Just addressing your HTTP request...

    If all you are doing is making a simple request and not needing a lot
    of control over how LWP behaves, then use LWP::Simple.

    Then your request becomes a simple get('url') call, which returns
    whatever the server sent.
     
    gf, Feb 15, 2007
    #3
  4. RogerF

    Brian Wakem Guest

    gf wrote:

    > Just addressing your HTTP request...
    >
    > If all you are doing is making a simple request and not needing a lot
    > of control over how LWP behaves, then use LWP::Simple.
    >
    > Then your request becomes a simple get('url') call, which returns
    > whatever the server sent.



    Minus the headers.


    --
    Brian Wakem
    Email: http://homepage.ntlworld.com/b.wakem/myemail.png
     
    Brian Wakem, Feb 15, 2007
    #4
  5. RogerF

    gf Guest

    On Feb 15, 10:56 am, Brian Wakem <> wrote:

    > Minus the headers.


    Correct, but sometimes that's desirable.
     
    gf, Feb 15, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Birtle
    Replies:
    2
    Views:
    2,181
    John Saunders
    Oct 16, 2003
  2. Replies:
    6
    Views:
    6,047
    Tor Iver Wilhelmsen
    Aug 29, 2005
  3. James
    Replies:
    3
    Views:
    16,616
    Roedy Green
    Nov 25, 2005
  4. nRk
    Replies:
    1
    Views:
    1,039
    Steven D'Aprano
    Feb 12, 2009
  5. Gelonida N
    Replies:
    0
    Views:
    550
    Gelonida N
    Feb 27, 2012
Loading...

Share This Page