How to submit an HTTP Request with XML

K

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
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> said:
</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> said:
</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
 
J

J. Gleixner

kwalike57 said:
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
 
K

kwalike57

kwalike57 said:
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
</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
 
B

Ben Morrow

Quoth kwalike57 said:
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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top