powerhouse has asked for the wisdom of the Perl Monks concerning the following question:
LWP Code:use Net::SSLeay qw(get_https post_https sslcat make_headers make_form) +; my $page = ''; my $response = ''; my %headers = ''; use XML::Bare; my $server = 'api.path.com; my $path = '/further/http_path/fileName.asp?getInsteadOfPostVAR1='. +$username.'&getInsteadOfPostVAR2='.$password.'getInsteadOfPostVAR3='. +$accountId; my $port = '443'; # url encoded for redirect after card successfully ordered on the payo +neer website... my $_redirectURL = qq~https%3A%2F%2Fwww%2EencodedURL%2Enet%2Findex%2Ec +gi%3Fpg%3DBackOffice%26do%3Drfp%26un%3D$_username~; my $_xmlToSend = qq~<?xml version='1.0' encoding='UTF-8' ?><PayoneerDe +tails><Credentials><userName>$_apiUsername</userName><password>$_apiP +assword</password></Credentials><Details><prid>$_apiAccountId</prid>< +apuid>$_memberId</apuid><sessionid></sessionid><redirect>$_redirectUR +L</redirect><redirectTime>3</redirectTime><cardType>MC</cardType></De +tails><PersonalDetails><firstName>$_database->{FirstName}</firstName> +<lastName>$_database->{LastName}</lastName><dateOfBirth></dateOfBirth +><address1>$_database->{address}</address1><address2>$_database->{add +ress2}</address2><city>$_database->{city}</city><country>$_databaseco +untry</country><state>$_databasestate</state><zipCode>$_database->{zi +p}</zipCode><mobile>$_database->{cell}</mobile><phone>$_database->{ph +one}</phone><email>$_database->{email}</email></PersonalDetails></Pay +oneerDetails>~; my %submit_data = ( 'mname' => "GetXML", 'xml' => "$_xmlToSend", ); my $post_data = &make_form(%submit_data); my ($page,$response,%headers) = &post_https($server,$port,$path,'',$po +st_data); my $ob = new XML::Bare( text => "$page" ); my $root = $ob->parse(); my $_redirectUrl = $root->{PayoneerToken}{Token}{value}; #Get Data to see if it worked: die "\$_redirectUrl = '$_redirectUrl';\$post_data='$post_data';<br>\$p +age='$page';"; window_redirect($_redirectUrl); exit;
Both return the same response(displayed in browser from die statements):#Using the same variables above for data: use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->agent("Mozilla/8.0"); # pretend we are very capable browser $ua->cookie_jar({ file => "$ENV{HOME}/.cookies.txt" }); push @{$ua->requests_redirectable}, 'POST'; my $req = HTTP::Request->new(POST => 'https://'.$server.$path); $req->content_type('application/x-www-form-urlencoded'); $req->content('mname=GetXML&xml='.$_xmlToSend.'&submit=Choice'); $req->referer('https://www.OurDomainHere.net/index.cgi?pg=BackOffice') +; # Pass request to the user agent and get a response back my $res = $ua->request($req); if ($res->is_success) { $page=$res->content; } # Now go down to where xml::bare parses data.... and die to check if i +t works...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Posting xml in a form behind the scenes
by Corion (Patriarch) on Dec 15, 2009 at 08:35 UTC |