Hi, I am trying to push files in a given directory, passed as a parameter, recursively. The file need to be base64 encoded and the destination accepts the file in a specific SOAP request. When I print the file into a notepad, it looks good but thru CURL.exe run through curl command, the response I am getting is ... Malformed content (from client), which means the request is not well-formed. I believe there is something I am missing here. Please see the code below and suggest your comments for making it to work, please.
use strict; use File::Find; use MIME::Base64; sub loadFiles(); #udf sub mySub(); #udf my @files = (); my $dir = shift || die "Argument missing: directory name\n"; my $finalLoc; my $filePath; my $fileContents; my $base64EncFile; my $domain="TEST"; my $devFilePath; my $deviceDir; my $position; my $user="USER"; my $encPwd="VVNFUjEyMw=="; my $decPwd; loadFiles(); #call foreach (@files) { $filePath = $_; #replace / to \ in the directory path $filePath =~ s/\//\\/g; $devFilePath = $_; # replace \ to / when setting a file path into the target location $devFilePath=~ s/\\/\//g; $position = index($devFilePath, "RPDM"); #take a substring after the RPDM location and add that to the stri +ng below $deviceDir = "local:///".substr($devFilePath, $position); #open a file using FILE handle open( FILE, "< $filePath" ); # take all file contents into a variable $fileContents = do { local $/; <FILE> }; #base-64 encode the file contents and store into a variable $base64EncFile = encode_base64($fileContents); #flatten the string by removing <CR><LF> characters $base64EncFile =~ s/[\x0A\x0D]//g; #save the web service request into a variable my $dpString = "<env:Envelope xmlns:env='http://schemas.xmlsoap.or +g/soap/envelope/' xmlns:dp='http://www.datapower.com/schemas/manageme +nt'><env:Body><dp:request domain='$domain'><dp:set-file name='$device +Dir'>".$base64EncFile."</dp:set-file></dp:request></env:Body></env:En +velope>"; #decode the above encoded password $decPwd=decode_base64($encPwd); #make a curl command to submit the web-service request at the dest +ination end-point system('C:\\apps\\curl-7.15.0\\curl.exe -# -k -u admin:$decPwd --d +ata-binary $dpString https://host:1234/services/endPoint'); close(FILE); } sub loadFiles() { find( \&mySub, "$dir" ); #custom subroutine find, parse $dir } # following gets called recursively for each file in $dir, check $_ to + see if you want the file! sub mySub() { push @files, $File::Find::name if (/(\.xml|\.xsl|\.xslt|\.ffd|\.dpa|\.wsdl|\.xsd)$/i) ; # modify the regex as per your needs or pass it as another +arg }
Appreciate the help. Thank you.

In reply to Using Windows Curl.exe in Perl by liv2luv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.