#!/usr/bin/perl use LWP::UserAgent; # PLD TEST URL $upsURL = "https://www.pld-certify.ups.com/hapld/tos/kdwhapltos"; # open and read the pld0200 file open(PLDDAT, "<c:\\temp\\[filename]") || die "can not open pld File"; $pldFileContent =Note: In a production environment it is recommend adding also some code for error handling; close(PLDDAT); # create message part 1 $msg_part1 = "AppVersion=1.0&AcceptUPSLicenseAgreement=YES&ResponseType=application/x-ups-pld&VersionNumber=V4R1&UserId=PLDDSTEST&Password=PLDDSTEST"; $msg_part1_header1 = "Content-type: application/x-www-form-urlencoded"; $msg_part1_header2 = "Content-length: ".length($msg_part1); $msg_part1 = $msg_part1_header1."\r\n".$msg_part1_header2."\r\n\r\n".$msg_part1; # create message part 2 $msg_part2 = $pldFileContent; $msg_part2_header1 = "Content-type: application/x-ups-binary"; $msg_part2_header2 = "Content-length: ".length($msg_part2); $msg_part2 = $msg_part2_header1."\r\n".$msg_part2_header2."\r\n\r\n".$msg_part2; # create the complete request message $PLDmsg = "--BOUNDARY\r\n".$msg_part1."\r\n\r\n--BOUNDARY\r\n".$msg_part2."\r\n\r\n--BOUNDARY--"; # Create the new request my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => $upsURL); # set the Request headers $req->content_type('multipart/mixed; boundary=BOUNDARY'); $req->content_length(length($PLDmsg)); # Request $req->content($PLDmsg); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the response if ($res->is_success) { $response = $res->content; } else { $response = $res->status_line; } print $response; # add the code for parsing the response
Copyright © 2003 United Parcel Service Deutschland Inc. & Co. OHG