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

Hi,

I am trying to make an api call with xml however every time i make the call i get an error. The only workaround i could come up with was to

1) save the xml request to a text file.

2) Load the $request back in and assign to a $ string

3) then make the call.

Can anyone tell me a reason why this is happening and a method to make the call without first saving/loading the file?

# define the XML request (REVISE) if ($econfig =~ /ReviseInventoryStatusRequest/ ) { $req1 = "<?xml version='1.0' encoding='utf-8'?>" . "<ReviseInventoryStatusRequest xmlns=\"urn:ebay:apis:eBLBaseComponents +\">" . "<RequesterCredentials>". "<eBayAuthToken>$token</eBayAuthToken>". "</RequesterCredentials>". "<ErrorLanguage>en_US</ErrorLanguage>". "<WarningLevel>High</WarningLevel>". "<InventoryStatus>". "<ItemID>$uuid</ItemID>". "<StartPrice>$myprice1</StartPrice>". # "<Quantity>4</Quantity>" . "</InventoryStatus>". "</ReviseInventoryStatusRequest>"; } # POST VIA SINGLE CALL API if ($apipost == 1) {$apipost = 0 ; # WRITE THE XML REQUEST TO FILE open (UPCWRITE, '>apirequest1.txt');print UPCWRITE "$req1 stop\n";clos +e(UPCWRITE); # LOAD THE XML REQUEST BACK IN print "WOOT";print "$req1";open(F,'apirequest1.txt');@req1=<F>;close F +;$request ="@req1"; # make the call my $objRequest = HTTP::Request->new( "POST", "https://api.ebay.com/ws/api.dll", $objHeader, $request ); # deal with the response my $objUserAgent = LWP::UserAgent->new; my $objResponse = $objUserAgent->request($objRequest); if (!$objResponse->is_error) { print $objResponse->content;} else {pri +nt $objResponse->error_as_HTML;} } # if ($apipost == 1)

Replies are listed 'Best First'.
Re: Formatted XML is not formatted:
by ikegami (Patriarch) on Mar 02, 2011 at 23:50 UTC

    Do the following for a request that works and one that doesn't, then compare the results.

    { require Data::Dumper; local $Data::Dumper::Useqq = 1; print(STDERR Data::Dumper::Dumper($request)); }

    I suspect you might need to encode $request. If so, and if you have warnings on as you should, you should be getting "Wide character in print" with the code you posted.

Re: Formatted XML is not formatted:
by GrandFather (Saint) on Mar 02, 2011 at 23:12 UTC

    What did the code look like without the save/load?

    There is odd stuff going on during the save/load process that looks like it wouldn't happen otherwise like the addition of stop \n to the end of the request string and the "@req1" string interpolation step which may add some extra white space to the request.

    True laziness is hard work