I am trying desperately to send a form behind the scenes so I can get the response and send the visitor to where they need to go.
(Responds with a unique URL for the visitor to have to visit to order their commission card so we can put their commissions on their cards for them)

I've tried using both use Net::SSLeay qw(get_https post_https sslcat make_headers make_form); and use LWP::UserAgent, here is my code for both:

code for Net::SSLeay
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;
LWP Code:
#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...
Both return the same response(displayed in browser from die statements):

$_redirectUrl = '';$post_data='p2=HiddenPassword&p3=HiddenAccountId&p1=HiddenUsername&mname=GetXML;
$page='<?xml version='1.0' encoding='ISO-8859-1' ?><PayoneerResponse><Error><Code>FFA009A</Code><Description>Auto populate XML contains invalid entries</Description></Error></PayoneerResponse>'

That is what prints from the die statement no matter which code I run...
Yet if I take the xml that I have post in a die statement elsewhere and put it in a form and post directly
through the form in the browser to that url, I get the correct xml response...

So something is wrong with this code, somewhere.

I think it may be the passing of a varible in a string: &xml=<?xml version='1.0' encoding='ISO-8859-1' ?> the spaces there may be the problem, not sure why... anyhow, do you know of a way to get that form posted as if a browser posted it directly without having to put the xml in a string which may cause errors on the receiving end?

I would greatly appreciate the advice of any of you monks or visitors that have a clue...

Thanks,
Richard

In reply to Posting xml in a form behind the scenes by powerhouse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.