[ic] UPS Shipping Hack - Mike! HELP!

Jason Osborne interchange-users@lists.akopia.com
Wed Jul 18 15:26:01 2001


Mike, List,

Goal: Design a globalsub that can be called during order processing to setup
UPS to pick up the items ordered, print off a shipping label, and grab the
tracking number. This globalsub will allow those people who do not meet UPS'
50+ package-a-day E-Commerce Solution program. It will allow for easy
integration of shipping into the current system allowing the shipping
department in an organization to be able to automate each part of the
shipping process.

Solution: Send any information the shipping section of UPS.com needs to the
iis.class file located on their servers. Do general error checking and pull
off tracking number from site.

Problem: UPS.com requires a login and password to access the shipping part
of the site. I hacked out a script that sends this information via
Net::SSLeay, however, the site tries to send back a cookie to the "client".
The globalsub needs to be able to anticipate and accept this cookie and keep
it on file so that it can "trick" UPS.com into thinking it is a browser.

Code and current results are below.

CODE

#!/usr/bin/perl

    my %query = (
                    userid              => 'user',
                    password            => 'passwd',


    );

    my @query;

    for (keys %query) {
        my $key = $_;
        my $val = $query{$key};
        $val =~ s/["\$\n\r]//g;
        $val =~ s/\$//g;
        my $len = length($val);
        if($val =~ /[&=]/) {
            $key .= "[$len]";
        }
        push @query, "$key=$val";
    }
    my $string = join '&', @query;

print "$string\n";

    use Net::SSLeay qw(post_https make_form make_headers);

    my ($page, $response, %reply_headers) = post_https("www.ups.com", "443",
"/servlet/login",
       make_headers( Referer => "www.ups.com"), make_form(%query));


print "$page\n\n\n";
print "$response\n\n\n";
print "%reply_headers\n\n\n";

# Thought about using LWP::UserAgent's cookie_jar to accept the cookies,
# but am unsure how to integrate the two.

#        require LWP::UserAgent;
#        $ua = new LWP::UserAgent;

#        $request = new HTTP::Request('GET', 'file://localhost/etc/motd');

#        $response = $ua->request($request); # or
#        $response = $ua->request($request, '/tmp/sss'); # or
#        $response = $ua->request($request, \&callback, 4096);

#        sub callback { my($data, $response, $protocol) = @_; .... }


RESPONSE

Currently, UPS.com comes back with the following:
You must accept cookies in your browser to access MY UPS.COM.  After
enabling cookies in your browser, <A
HREF="https://www.ups.com/servlet/login?returnto=http%3A%2F%2Fwww.ups.com%2F
">Log In</A> again.<p>See Internet Shipping Tips for further information.


Thanks,

Jason Osborne
Data and Telecom Network Solutions
3847 Timberglen Rd., STE 4013
Dallas, Texas 75287
phone: 972-307-0676
fax:   972-662-7956
e-mail: sales@sohonetworks.cc
web: http://www.sohonetworks.cc