Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Using Windows Curl.exe in Perl

by liv2luv (Initiate)
on Apr 26, 2012 at 12:57 UTC ( [id://967337]=note: print w/replies, xml ) Need Help??


in reply to Re: Using Windows Curl.exe in Perl
in thread Using Windows Curl.exe in Perl

Thanks Rob. That worked! Have a follow-up question though - for files over 100kb, I am getting an error: Can't spawn "cmd.exe": No such file or directory Looked around to see but could not find anything that works. Can you please throw some light here, please. Thanks again.

Replies are listed 'Best First'.
Re^3: Using Windows Curl.exe in Perl
by Anonymous Monk on Apr 26, 2012 at 13:14 UTC
      Thank you for the pointer to use File::Temp module. Able to generate a temporary file name but not sure how to write the content from a string into the temp file, simple assignment does not work viz., $tempFile = $stringValue; Following is my code, please advice:
      use strict; use File::Find; use MIME::Base64; use File::Temp qw(tempfile); 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 = "ABC"; my $devFilePath; my $deviceDir; my $position; my $user = "admin"; my $encPwd = "kaosapdkasd="; my $decPwd; my $response; my $temp; my $tempFilename; loadFiles(); #call #map ({ print "$_\n"; } @files); foreach (@files) { $filePath = $_; $filePath =~ s/\//\\/g; $devFilePath = $_; $devFilePath =~ s/\\/\//g; $position = index( $devFilePath, "RPDM" ); $deviceDir = "local:///" . substr( $devFilePath, $position ); open( FILE, "< $filePath" ); $fileContents = do { local $/; <FILE> }; $base64EncFile = encode_base64($fileContents); $base64EncFile =~ s/[\x0A\x0D]//g; #creating a temp file to be able to set large files (~500 kb) $temp = File::Temp->new( TEMPLATE => "tempXXXXXXXXX", UNLINK => 0 ) or die "Could not make tempfile: $!"; close $temp or die "Could not close tempfile: $!"; $tempFilename = $temp->filename; print "$filePath\n"; print "$tempFilename \n"; my $dpString = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' x +mlns:dp='http://www.datapower.com/schemas/management'><env:Body><dp:r +equest domain='$domain'><dp:set-file name='$deviceDir'>" . $base64EncFile . "</dp:set-file></dp:request></env:Body></env:Envelope>"; $decPwd = decode_base64($encPwd); #***HOW TO GET THE CONTENTS FROM $dpString INTO $tempFilename OTHER TH +AN SIMPLE ASSIGNMENT ? $tempFilename = $dpString; #print "\n$dpString\n"; #$response = system('C:\\apps\\curl-7.15.0\\curl.exe', '-#', '-k', '-u +', "admin:$decPwd", '--data-binary', "$dpString", 'https://hostxyz:55 +50/service/mgmt/current'); # print "$response\n"; system( 'C:\\apps\\curl-7.15.0\\curl.exe', '-#', '-k', '-u', "admin:$decPwd", '--data-binary', "$dpString", 'https://hostxyz:5550/service/mgmt/current' ); close(FILE); print "\n--------------------------------------------------------- +--\n"; } 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 }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://967337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 23:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found