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

Hello - I'm trying to post XML via HTTP POST and am getting back from the server: "Missing parameter: labelRequestXML." The transport works-- I can use the commands minus the xml code to communicate successfully with the server. Indeed, since I get the error response, I know I'm communicating with the server. I have validated the xml part with their server (using their own HTTP POST test tool). So, I'm thinking that somehow I'm not properly formatting or submitting the xml code part, as they're getting the request and responding- just not recognizing the xml code for what it is. I've tried many (many) variations. I'm stuck. Any help would be most appreciated! Thanks - Josh
Code is as follows:
#!/usr/bin/perl use strict; use warnings; use LWP 5.64; my $browser = LWP::UserAgent->new; my $xml= qq[<?xml version="1.0" encoding="utf-8" ?> <LabelRequest Test="YES" LabelType="Default" LabelSize="4X6" ImageForm +at="PNG"> <RequesterID>xxxxxx</RequesterID> <AccountID>xxxxxx</AccountID> <PassPhrase>xxxxxx</PassPhrase> <MailClass>First</MailClass> <DateAdvance>0</DateAdvance> <WeightOz>15</WeightOz> <MailpieceShape>Parcel</MailpieceShape> <Stealth>FALSE</Stealth> <Services InsuredMail="OFF" SignatureConfirmation="OFF" /> <BarcodeFormat>CONCATENATED</BarcodeFormat> <Value>0</Value> <Description>Sample Label</Description> <PartnerCustomerID>12345ABCD</PartnerCustomerID> <PartnerTransactionID>6789EFGH</PartnerTransactionID> <ToName>Amine Khechfe</ToName> <ToCompany>PSI Systems, Inc.</ToCompany> <ToAddress1>247 High Street</ToAddress1> <ToCity>Palo Alto</ToCity> <ToState>CA</ToState> <ToPostalCode>84301</ToPostalCode> <ToZIP4>0000</ToZIP4> <ToDeliveryPoint>00</ToDeliveryPoint> <ToPhone>8005763279</ToPhone> <FromName>John Doe</FromName> <ReturnAddress1>123 Main Street</ReturnAddress1> <FromCity>Boise</FromCity> <FromState>ID</FromState> <FromPostalCode>83702</FromPostalCode> <FromZIP4>7261</FromZIP4> <FromPhone>8005551212</FromPhone> </LabelRequest>]; my $url = 'https://www.envmgr.com/LabelService/EwsLabelService.asmx/Ge +tPostageLabelXML'; my $response = $browser->post( $url, $xml ); print $response->content;

Replies are listed 'Best First'.
Re: Post XML
by derby (Abbot) on Dec 06, 2007 at 17:53 UTC

    It's hard to tell (since the issue is really on the server side). But it sounds like either the server wants the data to be form-data (labelRequestXML=<longstringofxml>) or it's doing different processing based on the the content-type. You can try setting the type:

    #!/usr/bin/perl use strict; use warnings; use LWP 5.64; my $browser = LWP::UserAgent->new; my $xml= qq[<?xml version="1.0" encoding="utf-8" ?> .... snip .... ]; my $url = 'https://www.envmgr.com/LabelService/EwsLabelService.asmx/Ge +tPostageLabelXML'; my $response = $browser->post( $url, Content_Type => 'text/xml', Content => $xml ); print $response->content;
    or if it wants form data
    my $response = $browser->post( $url, Content => [ labelRequestXML => $xml ] );
    -derby
      Derby- Thank you VERY much. Your suggestion:
      Content => [ labelRequestXML => $xml ]
      ...was exactly what was needed. - Josh