Help with POST request using LWP?

Discussion in 'Perl Misc' started by at, Dec 6, 2003.

  1. at

    at Guest

    Thanks for reading.

    I am trying to use LWP to logon then send a request to a remote server
    and capture its response for further processing.

    So far I've been able to perform the initial connect, retrieve a 2nd
    URL and login using https and capture a server assigned cookie as a
    response.

    Now I am attempting to make the actual request which resides in a disk
    file.

    The specifications state that the request MUST be send in this was:
    "The body of the POST request contains the request parameter
    NETCONNECT_TRANSACTION and the value is the encoded XML request.
    The entire XML request must be encoded using a MIME format called
    "x-www-form-urlencoded" format.".

    So, based on my very limited LWP knowledge and the best I could gather
    from various tech publications, lwpcook, and usenet examples is the
    following code snippet:

    ==========================
    my $fname="CX7XML";
    open(TFH,"<CX7XML") or die "Cannot Open CX7XML\n";
    while(<TFH>) {
    $DATA.=chomp($_);
    }
    close(TFH);
    $REQ= POST $URL2;
    $REQ->content_type('application/x-www-form-urlencoded');
    $REQ->content_length(length($DATA));
    $REQ->content('NETCONNECT_TRANSACTION=$DATA');
    $RSP=$UA->request($REQ, "CX7RSP");

    ==========================

    What I receive from the host are the following headers:

    200 OK
    Cache-Control: no-store
    Connection: close
    Date: Fri, 05 Dec 2003 22:34:58 GMT
    Pragma: no-cache
    Accept-Ranges: bytes
    ETag: "27a4941a-1-4fa-3fc3ed96"
    Server: "EWS/1.11"
    Content-Length: 1274
    Content-Type: text/html
    Content-Type: text/html; charset=iso-8859-1
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    Last-Modified: Wed, 26 Nov 2003 00:02:30 GMT
    Last-Modified: 0
    Client-Date: Fri, 05 Dec 2003 22:32:33 GMT
    Client-Peer: 205.xxx.xxx.xxx:443
    Client-Response-Num: 1
    Client-SSL-Cert-Issuer: /C=US/O=RSA Data Security, Inc./OU=Secure
    Server Certification Authority
    Client-SSL-Cert-Subject: /C=US/ST=California/L=Costa Mesa/O=Xxxxxxxx
    Information Solutions Inc/OU=Technology
    Operations/CN=stg1-ss1.xxxxxxxx.com
    Client-SSL-Cipher: RC4-MD5
    Client-SSL-Warning: Peer certificate not verified
    Set-Cookie:
    ctrust-session-v002b=24oykHnpivFIsykCCrUU4/Xz/g+0B5h+BhQKrvkYqTKVfLTTAeIdEI+y1efpg5oshPz9G7ahhKTdGeh9rwosg0WNZ/vALoSkhK7/phTuI2caRKZAmo0TJgaGMIE7wMdS6y4mQLOTPjOrLSnEOuyKqupsftUAZXXI2R4jkkfs4hPpj+CTJWaXeWVpOI/1OiRbgIRXl3Xy9Lo=;domain=.experian.com;path=/;secure
    X-Meta-Description: SSO
    X-Meta-Keywords: SSO

    And just another "login" screen insteat of a returned XML file that I
    would receive if successful.

    I've tried literally dozens and dozens of code methods based on LWP
    examples but the all end up the same as the current one.

    Can anyone with LWP experience PLEASE try to point me to the area that
    I might be mis-understanding this process?

    Thanks a million.

    Bob
    at, Dec 6, 2003
    #1
    1. Advertising

  2. at

    Bob Walton Guest

    at Bob Mariotti wrote:

    ....


    Just a guess...


    > $REQ->content('NETCONNECT_TRANSACTION=$DATA');


    "---------------^----------------------------^
    Note that $DATA is not interpolated using '...' quotation.

    ....
    > Bob


    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
    Bob Walton, Dec 6, 2003
    #2
    1. Advertising

  3. at

    Ben Morrow Guest

    R.Mariotti(at)FinancialDataCorp.com (Bob Mariotti) wrote:
    > $REQ= POST $URL2;
    > $REQ->content_type('application/x-www-form-urlencoded');
    > $REQ->content_length(length($DATA));
    > $REQ->content('NETCONNECT_TRANSACTION=$DATA');


    You should be creating your request with:

    my $REQ = POST $URL2, [ NETCONNECT_TRANSACTION => $DATA ];

    or indeed simply using

    my $RSP = post $UA $URL2,
    [ NETCONNECT_TRANSACTION => $DATA ],
    ':content_file' => "CX7RSP";

    , either of which will properly deal with URLencoding the XML.

    Ben

    --
    It will be seen that the Erwhonians are a meek and long-suffering people,
    easily led by the nose, and quick to offer up common sense at the shrine of
    logic, when a philosopher convinces them that their institutions are not based
    on the strictest morality. [Samuel Butler, paraphrased]
    Ben Morrow, Dec 6, 2003
    #3
    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. Rubel Kanubel

    Post radiobuttons (forms) using lwp-useragent

    Rubel Kanubel, Oct 12, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    227
    Anno Siegel
    Oct 13, 2003
  2. Andrew
    Replies:
    1
    Views:
    348
    Gunnar Hjalmarsson
    Dec 5, 2003
  3. Zapanaz
    Replies:
    4
    Views:
    130
    Tad McClellan
    Oct 12, 2005
  4. prakash

    POST MIME Content using LWP

    prakash, Oct 26, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    92
    prakash
    Oct 26, 2005
  5. schruthensis
    Replies:
    18
    Views:
    785
    Matt Garrish
    Jan 7, 2006
Loading...

Share This Page