Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to submit an HTTP Request with XML

Reply
Thread Tools

How to submit an HTTP Request with XML

 
 
kwalike57
Guest
Posts: n/a
 
      03-10-2008
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
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      03-10-2008
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
 
Reply With Quote
 
 
 
 
kwalike57
Guest
Posts: n/a
 
      03-11-2008
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
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      03-11-2008

Quoth kwalike57 <(E-Mail Removed)>:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
urllib2.Request:: http Request sending successfully, but Responsecontains in valid data. nRk Python 1 02-12-2009 12:53 AM
How to modify http header when submit request from IE? walter ASP .Net 2 07-21-2008 08:20 PM
HTTP::Request::Form - Can't submit a form with input type=image button fochie Perl Misc 0 02-01-2005 06:42 AM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM



Advertisments