Here is my problem:

I have a CGI script that generates data. From this script, I want to call a second script, and pass it the data. That second script uses CGI.pm to access the posted data.

This works well, using LWP::UserAgent, building a request that includes a file and getting back the result:

sub upload { my( $data)= @_; my $ua = LWP::UserAgent->new; my $req= POST $SCRIPT_URL, Content_Type => 'form-data', Content => [ status => 'ok', uploaded_file => [ undef, # conte +nt provided below $basename, Content_Type = +> 'text/html', Content = +> $data ], ], ; # this might be wrong, the real code uses a callback to output the + results # as they come back from $SCRIPT my $result= $ua->request($req)->content; }

Now my problem is that both scripts are in protected areas, and are used by users whose passwords I do not know. So even if the above code works well on my test machine, I can't actually use it on the live server, because I cannot pass the credentials to the second script. And I cannot modify that script to bypass the authentication process.

The solution I have found, as both scripts are on the same machine, is to call directly the script, without going through the server. So I thought I would just set $ENV{REMOTE_USER}, build the same HTTP::Request as previously and pass the request content to the script. But none of this seems to work. The second script does not pick up the parameters, and the REMOTE_USER is not set.

Here is the code I have so far:

sub exe_script { my( $data)= @_; my $req= POST $SCRIPT, Content_Type => 'form-data', Content => [ status => 'ok', uploaded_file => [ undef, # cont +ent provided below 'whatever', Content_Type +=> 'text/html', Content +=> $data, ], ], ; open( my $script, "| $SCRIPT") or exit_status( Error => "cannot ca +ll script: $!"); my $user= remote_user(); $ENV{REMOTE_USER}= $user; my $content= $req->content; print {$script} $content; exit; }

Am I missing something obvious? Should I forget about HTTP::Request in this case, just RTFR (Read The Fine RFC) and build the request myself? And how can I get the REMOTE_USER variable set in $SCRIPT? Save the query in a file, set the environment variable and exec the script? That's my next experiment anyway.

Any help would be greatly appreciated


In reply to HTTP::Request to local script by mirod

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.