kdmurphy001 has asked for the wisdom of the Perl Monks concerning the following question:

Hello again Quasi-Divine Monk,

Once again I need to call upon your vast knowledge in my question to better understand all things perl.

The code below works if I replace the variable $Token with the actual token generated from the first cURL statement but if I use the code shown below it does not (IE instead of the actual token using $Token). I've tried enclosing the variable in single and double quotes, single+double quotes and vice versa, and sigle+double+singe quotes and double+single+double quotes. Nothing works. It spits out the XML shown below the code snippet in all instances. The 2nd cURL statement is where I believe the problem lies (this is the cURL statement using the token generated in the first cURL statement).
#!/usr/bin/perl use XML::Simple; use Data::Dumper; use strict; use warnings; my $HOST1='https://ws.fluffybunnies.com/zyxws/zyxws'; my $HOST2='https://ws.fluffybunnies.com/xyzws/xyzws'; my $ADMIN_UID='rabbit.lover@rabbits.com'; my $ADMIN_PASS= $ARGV[0]; my $Token=''; my $Title=''; $Token = `curl --insecure -Ss -d '<?xml version="1.0" ?><S:Envelope xm +lns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns5:getTok +en xmlns:ns2="java:com.tl.zyxws" xmlns:ns3="java:language_builtins.la +ng" xmlns:ns4="java:com.tl.zyxws.parameters" xmlns:ns5="http://ws.flu +ffybunnies.com:80/zyxws"><ns4:password>'$ADMIN_PASS'</ns4:password><n +s4:uid>'$ADMIN_UID'</ns4:uid></ns5:getToken></S:Body></S:Envelope>' - +-header "Content-Type: text/xml; charset=utf-8" $HOST1 | egrep -o '[A +-Z0-9]{32,}'`; print "Token: ".$Token."\n"; $Title = `curl --insecure -Ss -d '<?xml version="1.0" ?><S:Envelope xm +lns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns5:getTit +le xmlns:ns2="java:com.tl.xyzws" xmlns:ns3="java:language_builtins.la +ng" xmlns:ns4="java:com.tl.xyzws.parameters" xmlns:ns5="http://ws.flu +ffybunnies.com:80/xyzws"><ns4:isbn>123456789</ns4:isbn><ns4:epi>12121 +212121212121212</ns4:epi><ns4:token>'$Token'</ns4:token></ns5:getTitl +e></S:Body></S:Envelope>' --header "Content-Type: text/xml; charset=u +tf-8" $HOST2`; my $xml = new XML::Simple; my $data = $xml->XMLin($Title);


The output throws no errors but the Dumper spits out the following. I'll add that I could not find a good way to display this /w the wrapping so I shortened (the output does not look like this exactly, white space was removed).

$VAR1 = {
'soap:Body' => {
'ns5:getTitleResponse' => {
'xsi:nil' => 'true',
'xmlns:ns4' => 'java:language_builtins.lang',
'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:ns3' => 'java:com.tl.xyzws.parameters',
'xmlns:ns5' => 'http://ws.fluffybunnies.com:80/olrws',
'xmlns:ns2' => 'java:com.tl.xyzws'
}
},
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/'
};


With the actual token instead of the above I get the expected XML (title info, ect). It's wonderful except I don't want to have to manually paste in the title when this script is run since ideally I'll be using this in an automated process.

Thank you again for any help you can provide and I'll add that I'm in a bash shell on Unix(Debian).

Kevin M

Replies are listed 'Best First'.
Re: System tick and CURL not interrpeting variable
by NetWallah (Canon) on Dec 12, 2015 at 00:33 UTC
    Does $Token contain any characters that need to be escaped in HTML ?

    Perhaps when you copy/paste them into IE, it escapes those for you.

            "I can cast out either one of your demons, but not both of them." -- the XORcist

Re: System tick and CURL not interrpeting variable
by Anonymous Monk on Dec 12, 2015 at 00:59 UTC
    avoid the shell, use system with Capture::Tiny
    #!/usr/bin/perl -- use strict; use warnings; use Capture::Tiny qw/ capture /; use Data::Dump qw/ dd /; my @cmd = ( 'python', '-V' ); my( $stdout, $stderr, $exit ) = capture { system { $cmd[0] } @cmd; };; dd({ stdout => $stdout, stderr => $stderr, exit => $exit } ); __END__ { exit => 0, stderr => "Python 2.5\n", stdout => "" }
      avoid the shell, use system with Capture::Tiny

      Avoid the shell AND curl, use one of perl's HTTP libraries like LWP, or, in this case, use a SOAP library.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)