How to submit an HTTP Request with XML

Discussion in 'Perl Misc' started by kwalike57, Mar 10, 2008.

  1. kwalike57

    kwalike57 Guest

    Hello. I need to build a process in an existing Perl script the
    submits an http request with some XML.

    I have never done this in Perl and I need to know which modules to use
    and how to compose the syntax in the script to send this request.

    Here is what the fully composed request needs to look like:

    http://ppld.corp.sprint.com/wlsapps2/livelink_wls/Upload91?control=<?xml
    version="1.0" encoding="ISO-8859-1"?><LIVELINKUPLOAD ID="1"><LOADINFO
    Host="DOC-SHARE" LOGIN="xxxxxxx" PASSWORD="xxxxxxx"
    DELETESOURCE="TRUE" OUTPUT="XML" LOADTYPE="PATH"/><FILEINFO
    FILENAME="TRS_926106383.pdf"
    FTPFILENAME="926106383.pdf"><FOLDERPATH><FOLDER
    FOLDERNAME="Information Technology"/></FOLDERPATH><FOLDERPATH><FOLDER
    FOLDERNAME="IT Billing and Customer Care Systems (CBS)"/></
    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="CBS - Customer Billing
    Services"/></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="TRS Billing"/
    ></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="2007"/></

    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="Invoices"/></FOLDERPATH></
    FILEINFO></LIVELINKUPLOAD>

    If I paste this request string into a browser from the host machine
    where the Perl script will run from it executes perfectly, basically
    taking the .pdf file named in the command and uploading it to an
    online document library called Doc-Share where it is then viewable to
    users who log in.

    It also deletes the source .pdf file from an SFTP server where
    the .pdf files reside prior to upload to Doc-Share.

    Please let me know how I would add this automation to Perl.

    I have already written the Perl to generate the XML containing the
    name of each .pdf file that needs to upload. I have used the
    XML:Simple to parse the XML string and hold it in a variable, "<?xml
    version="1.0" encoding="ISO-8859-1"?><LIVELINKUPLOAD ID="1"><LOADINFO
    Host="DOC-SHARE" LOGIN="xxxxxxx" PASSWORD="xxxxxxx"
    DELETESOURCE="TRUE" OUTPUT="XML" LOADTYPE="PATH"/><FILEINFO
    FILENAME="TRS_926106383.pdf"
    FTPFILENAME="926106383.pdf"><FOLDERPATH><FOLDER
    FOLDERNAME="Information Technology"/></FOLDERPATH><FOLDERPATH><FOLDER
    FOLDERNAME="IT Billing and Customer Care Systems (CBS)"/></
    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="CBS - Customer Billing
    Services"/></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="TRS Billing"/
    ></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="2007"/></

    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="Invoices"/></FOLDERPATH></
    FILEINFO></LIVELINKUPLOAD>" .

    I have the http request in a separate variable as "http://
    ppld.corp.sprint.com/wlsapps2/livelink_wls/Upload91?control=".

    I then plan on running the http request with the XML string for
    each .pdf file, 46 .pdf files in all.

    Let me know if I need to provide any additional info to better
    describe the process.

    Thanks for your help.

    Karin Walike
    kwalike57, Mar 10, 2008
    #1
    1. Advertising

  2. kwalike57

    J. Gleixner Guest

    kwalike57 wrote:
    > Hello. I need to build a process in an existing Perl script the
    > submits an http request with some XML.
    >
    > I have never done this in Perl and I need to know which modules to use
    > and how to compose the syntax in the script to send this request.

    [...]

    To POST something via HTTP, you could start with LWP:

    perldoc lwpcook
    J. Gleixner, Mar 10, 2008
    #2
    1. Advertising

  3. kwalike57

    kwalike57 Guest

    On Mar 10, 11:06 am, "J. Gleixner" <glex_no-s...@qwest-spam-
    no.invalid> wrote:
    > kwalike57 wrote:
    > > Hello.  I need to build a process in an existing Perl script the
    > > submits an http request with some XML.

    >
    > > I have never done this in Perl and I need to know which modules to use
    > > and how to compose the syntax in the script to send this request.

    >
    > [...]
    >
    > To POST something via HTTP, you could start with LWP:
    >
    > perldoc lwpcook


    so would I just use LWP; or LWP::Simple;? Also, would I just do a
    straight $httprequest = get("http://ppld.corp.sprint.com/wlsapps2/
    livelink_wls/Upload91?control=<?xml
    version="1.0" encoding="ISO-8859-1"?><LIVELINKUPLOAD ID="1"><LOADINFO
    Host="DOC-SHARE" LOGIN="xxxxxxx" PASSWORD="xxxxxxx"
    DELETESOURCE="TRUE" OUTPUT="XML" LOADTYPE="PATH"/><FILEINFO
    FILENAME="TRS_926106383.pdf"
    FTPFILENAME="926106383.pdf"><FOLDERPATH><FOLDER
    FOLDERNAME="Information Technology"/></FOLDERPATH><FOLDERPATH><FOLDER
    FOLDERNAME="IT Billing and Customer Care Systems (CBS)"/></
    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="CBS - Customer Billing
    Services"/></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="TRS Billing"/


    ></FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="2007"/></



    FOLDERPATH><FOLDERPATH><FOLDER FOLDERNAME="Invoices"/></FOLDERPATH></
    FILEINFO></LIVELINKUPLOAD>"); or actually $httprequest = get($url .
    $xmldata); ??

    What do you think?

    Thanks!

    Karin Walike
    kwalike57, Mar 11, 2008
    #3
  4. kwalike57

    Ben Morrow Guest

    Quoth kwalike57 <>:
    > Hello. I need to build a process in an existing Perl script the
    > submits an http request with some XML.
    >
    > I have never done this in Perl and I need to know which modules to use
    > and how to compose the syntax in the script to send this request.
    >
    > Here is what the fully composed request needs to look like:
    >
    > http://ppld.corp.sprint.com/wlsapps2/livelink_wls/Upload91?control=<?xml
    > version="1.0" encoding="ISO-8859-1"?><LIVELINKUPLOAD ID="1"><LOADINFO

    <snip yards of XML>
    >
    > If I paste this request string into a browser from the host machine
    > where the Perl script will run from it executes perfectly, basically
    > taking the .pdf file named in the command and uploading it to an
    > online document library called Doc-Share where it is then viewable to
    > users who log in.


    That isn't a valid URL. At the very least all those spaces and
    question-marks need escaping; also, I seriously doubt you're meant to
    use a URL that long. I suspect you're meant to use POST instead of GET,
    especially as a non-reversible action like uploading a file should be a
    POST anyway (caches are required to pass POSTs on unmolested; this is
    not true of GETs). Probably it only works from the browser by accident: the
    browser 'helpfully' fixes your URL for you, and the server doesn't check
    that you used the correct HTTP method.

    Probably what you want is something like

    use LWP;

    my $url = # note this *doesn't* have ?content= on the end
    "http://ppld.corp.sprint.com/wlsapps2/livelink_wls/Upload91";
    my $xml = <<XML;
    <?xml version="1.0"?>
    ....
    XML

    my $UA = LWP::UserAgent->new;
    my $resp = $UA->post($url, content => $xml);

    $resp->is_success or die "POST failed: " . $resp->status_line;

    Ben
    Ben Morrow, Mar 11, 2008
    #4
    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,017
    John Saunders
    Oct 16, 2003
  2. walter
    Replies:
    2
    Views:
    842
    walter
    Jul 21, 2008
  3. nRk
    Replies:
    1
    Views:
    995
    Steven D'Aprano
    Feb 12, 2009
  4. Gelonida N
    Replies:
    0
    Views:
    526
    Gelonida N
    Feb 27, 2012
  5. fochie
    Replies:
    0
    Views:
    312
    fochie
    Feb 1, 2005
Loading...

Share This Page