Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting XML 1

Status
Not open for further replies.

solly45

Technical User
Sep 14, 2007
2
US
Hi,

I need to post an xml file to an .asp file : using perl and I'm not sure how to go about doing this.

I've created the xml file in my perl script, but I'm not clear on how to post this data?

Thanks,

Rich

Here's the data

<OrderList MerchantName="Widgets for Wadgets" MerchantId="12343444">
<Order id="9242">
<AddressInfo type="ship">
<Name>Jane Cass</Name>
<Company/>
<Address1>42200 Willow road</Address1>
<Address2/>
<City>Los Angeles</City>
<State>CA</State>
<Country>US</Country>
<Zip>90210</Zip>
<Phone>555-555-1333</Phone>
<Email>email@yahoo.com</Email>
</AddressInfo>
<AddressInfo type="bill">
<Name>Jane Doe</Name>
<Company/>
<Address1>42200 Willow road</Address1>
<Address2/>
<City>anywhere</City>
<State>CA</State>
<Country>US</Country>
<Zip>90210</Zip>
<Phone>555-555-1333</Phone>
<Email>email@yahoo.com</Email>
</AddressInfo>
<ShippingMethod>DHL Ground</ShippingMethod>
<ShippingMerchant>Widgets Inc.</ShippingMerchant>
<Greeting>Thanks for your order!</Greeting>
<Item num="0">
<ProductId>12343444-WIDGE1</ProductId>
<Quantity>1</Quantity>
<Unit-Price>26.00</Unit-Price>
</Item>
<Totals>
<Shipping>16.00</Shipping>
<Tax>0.00</Tax>
<SubTotal>26.00</SubTotal>
<GrandTotal>42.00</GrandTotal>
</Totals>
</Order>
</OrderList>
 
Code:
use LWP::UserAgent;
use HTTP::Request::Common;

my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');

my $req  = HTTP::Request->new(POST => $url);

$req->content_type('text/xml');
$req->content($data); # $data will be the string of xml

my $resp = $ua->request($req);
if ($resp->is_success) {
  print "SUCCESS: " . $resp->content();
}
else {
  print "FAILED: " . $resp->status_line();
}
 
That's great. Thank you so much.

I'll test the script and let you know the outcome.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top