#!/usr/bin/perl use LWP::UserAgent; use strict; my $url = 'https://usd.swreg.org/cgi-bin/token2order.pl'; my %form = ( shop_id => 5, # Your shop id token_id => '1', # The token id your are requesting information on. password => '********' # Your "Automated calls" password you specified in your author details. ); # Create the LWP::UserAgent object. if ( my $ua = LWP::UserAgent->new() ) { $ua->timeout(10); # Send request. my $response = $ua->post($url,\%form); if ( not $response ) { print STDERR "Post failed (Unknown error).\n"; } elsif ( $response->is_error() ) { print STDERR "Post failed: ",$response->status_line,"\n"; } else { my $content = $response->content(); # Split the content into an array. my @lines = split(/\r?\n/,$content); if ( scalar @lines > 0 ) { my %results = (); foreach my $line (@lines) { if ( $line =~ m/^(\w+)\:\s*(.+)$/ ) { $results{$1} = $2; } } # Do something with the results. # Example. print "StatusCode: $results{StatusCode}\n"; print "StatusMessage: $results{StatusMessage}\n"; # List of valid status codes and status messages. # 0 = Ok # 1 = Token not found # 2 = Access Denied # 3 = Invalid number of parameters specified. # 4 = System down for maintenance (Please try again later). # TokenId, OrderId, & ErrorCode are only return if StatusCode equals zero. if ( $results{StatusCode} == 0 ) { print "TokenId: $results{TokenId}\n"; print "OrderId: $results{OrderId}\n"; print "ErrorCode: $results{ErrorCode}\n"; } } else { print STDERR "Parse error of return from $url\n"; } } } else { print STDERR "Unable to create LWP::UserAgent object.\n"; }