Problem posting with LWP::UserAgent

J

john.eisenschmidt

Stuck in API hell, hoping someone can help me.

I'm trying to build a small webapp with mod_perl to connect to Oracle
Discoverer 10g and pass parameters based on who they are. Discoverer
used to have a CGI-like API within itself which you could just say:

http(s)://server.domain.com/discoverer/plus?us=user;pw=pass;etc

but they took that away for 10g and replaced it so it needs a CGI
redirect:


http://oraclebi.blogspot.com/2005/08/passing-password-to-viewer.html

<form name="dashboard redirect" action=$server method="POST">
Username: <input type="input" name="us" value=""><br>
Password: <input type="input" name="pw" value=""><br>
Workbook: <input type="input" name="wbk" value=""><br>
Worksheet: <input type="input" name="wsk" value=""><br>
Page Item: <input type="input" name="pi_Region" value="West"><br>
EUL: <input type="input" name="eul" value=""><br>
Database: <input type="input" name="db" value=""><br>
<input type="submit" name="submit" value="Submit">
</form>

Which I have working if I type in the params, but I want to build them
and shoot the user straight in. So I've tried a couple different ways
to do this, and none have worked:

sub connectToDiscoverer {
#########################################################################
# attempt 1:
#########################################################################
# use LWP::UserAgent;
# use HTTP::Request::Common;
# my $ua = LWP::UserAgent->new;
# my %tags = ();
# $tags{'us'} = 'jeisensc';
# $tags{'pw'} = '999999';
# $tags{'wbk'} = '0000 Budget_Check_Summary';
# $tags{'wsk'} = '';
# $tags{'pi_Region'} = 'West';
# $tags{'eul'} = '';
# $tags{'db'} = 'FOO';
#
# my $response = $ua->post(POST '/reports/discoverer.html',
#########################################################################
# tried both content_types here, not at same time
#########################################################################
# Content_Type => 'form-data',
# Content_Type => 'application/x-www-form-urlencoded',
# Content => [ %tags ]
# );
# if ($response->is_success) {
# print $response->content; # or whatever
# }
# else {
# die $response->status_line;
# }
# print $resp->error_as_HTML unless $resp->is_success;
# print $resp->content();

#########################################################################
# attempt 2
#########################################################################
#my $ua = LWP::UserAgent->new;
#########################################################################
# tried ->request and ->post, not at same time
#########################################################################
# my $response = $ua->post('http://localhost/reports/discoverer.html',
[
# my $response = $ua->request(POST
'http://localhost/reports/discoverer.html', [
# us => 'jeisensc',
# pw => '999999',
# wbk => '0000 Budget_Check_Summary',
# wsk => '',
# pi_Region => 'West',
# eul => '',
# db => 'FOO'
# ]);
#
# my %deref = %$response;
# print $deref{"_content"};
#########################################################################
# attempt 3
#########################################################################
use LWP::UserAgent;

my %tags = ();
$tags{'us'} = 'jeisensc';
$tags{'pw'} = '999999';
$tags{'wbk'} = '0000 Budget_Check_Summary';
$tags{'wsk'} = '';
$tags{'pi_Region'} = 'West';
$tags{'eul'} = '';
$tags{'db'} = 'FOO';

my $ua = new LWP::UserAgent;
my $req = new HTTP::Request
'POST','http://localhost/reports/discoverer.html';
$req->content_type('application/x-www-form-urlencoded');
$req->content(%tags);
my $res = $ua->request($req);

}; ## end connectToDiscoverer
#########################################################################

Am I missing something here? When I run in browser, I just get
"<html><head></head></html>" and then if I try from the shell I just
get nothing.

Thanks
 
J

J. Gleixner

Stuck in API hell, hoping someone can help me.

I'm trying to build a small webapp with mod_perl to connect to Oracle
Discoverer 10g and pass parameters based on who they are. Discoverer
used to have a CGI-like API within itself which you could just say:

http(s)://server.domain.com/discoverer/plus?us=user;pw=pass;etc

but they took that away for 10g and replaced it so it needs a CGI
redirect:


http://oraclebi.blogspot.com/2005/08/passing-password-to-viewer.html

<form name="dashboard redirect" action=$server method="POST">
Username: <input type="input" name="us" value=""><br>
Password: <input type="input" name="pw" value=""><br>
Workbook: <input type="input" name="wbk" value=""><br>
Worksheet: <input type="input" name="wsk" value=""><br>
Page Item: <input type="input" name="pi_Region" value="West"><br>
EUL: <input type="input" name="eul" value=""><br>
Database: <input type="input" name="db" value=""><br>
<input type="submit" name="submit" value="Submit">
</form>

Which I have working if I type in the params, but I want to build them
and shoot the user straight in. So I've tried a couple different ways
to do this, and none have worked:
[...]

Am I missing something here? When I run in browser, I just get
"<html><head></head></html>" and then if I try from the shell I just
get nothing.

The URL you listed shows

<input type="submit" name="connect" value="Connect">
^^^^^^^
I don't see that in your %tags. I'd guess the script is looking for that
parameter and its value.
 
J

john.eisenschmidt

Yeah my mistake, but the CGI lets you into Discoverer either way:

<form name="dashboard redirect" action=$server method="POST">
Username: <input type="input" name="us" value=""><br>
Password: <input type="input" name="pw" value=""><br>
Workbook: <input type="input" name="wbk" value=""><br>
Worksheet: <input type="input" name="wsk" value=""><br>
Page Item: <input type="input" name="pi_Region" value="West"><br>
EUL: <input type="input" name="eul" value=""><br>
Database: <input type="input" name="db" value=""><br>
<input type="submit" name="connect" value="Connect">
</form>

and I made the change to my parameter list and still didn't have any
luck:

use LWP::UserAgent;
use HTTP::Request::Common;

my $ua = LWP::UserAgent->new;
my %tags = ();
$tags{'us'} = 'jeisensc';
$tags{'pw'} = '999999';
$tags{'wbk'} = '0000 Budget_Check_Summary';
$tags{'wsk'} = '';
$tags{'pi_Region'} = 'West';
$tags{'eul'} = '';
$tags{'db'} = 'FOO';
$tags{'connect'} = 'connect';

my $response = $ua->post('http://localhost/discoverer.html',
Content_Type => 'form-data',
# Content_Type => 'or application/x-www-form-urlencoded',
Content => [ %tags ]
);
if ($response->is_success) {
print $response->content; # or whatever
}
else {
die $response->status_line;
}
print $response->error_as_HTML unless $response->is_success;
print $response->content();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top