Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debugging http post request 2

Status
Not open for further replies.

Perlwannabe

Technical User
Mar 7, 2006
57
IT
Hello,

Wondering what's wrong in that cgi script:

Code:
#!perl

  use HTTP::Request::Common qw(POST);
  use LWP::UserAgent;

  $ua = LWP::UserAgent->new;

  my $req = POST '[URL unfurl="true"]http://localhost/cgi-bin/control.cgi?newpage',[/URL]
                [ pass => 'blah' , text => 'xxx'];

print "Content-type: text/html\n\n";

  print $ua->request($req)->as_string;

It should pass a plan text to a form,but it doesn't work.
It connects to the page,show the form but any text is passed.

Could you enlight me,please?
Should I define an encoding method, maybe?

Thanks for your feedbacks

Sincerely
 
Is "as_string" part of the specification for LWP::UserAgent?


I would suggest that you simply follow the example used in the synopsis for getting the output:


Also, I believe that your use of ?newpage' in your POST will be ignored. If you're wanting to set a newpage cgi parameter, than it should be included in the following array ref parameter.
 
Hello MillerH and thanks for the reply.

>>>Is "as_string" part of the specification for LWP::UserAgent?

Yes.

>>>Also, I believe that your use of ?newpage' in your POST will be ignored. If you're wanting to set a newpage cgi parameter, than it should be included in the following array ref parameter.

The "?newpage" parameter is the required Action attribute of the form.
should I include it here?
Code:
 [ pass => 'blah' , action => 'newpage',text => 'xxx'];


 
Yes. control.cgi will now also receive the cgi parameter action=newpage.

Instead of asking though, why not just try it and tell us if it works? :)

g'luck.
 
Also,I would add that I cannot follow the examples you linked for me as I'm running Perl only as cgi script on Apache web server running under Win XP. So I haven't perl console...
 
Well the example that I gave you basically would have changed your code from

Code:
print $ua->request($req)->as_string;

to

Code:
my $response = $ua->request($req);
if ($response->is_success) {
    print $response->content;  # or whatever
} else {
    die $response->status_line;
}

I'm pretty sure that would work in whatever environment your coding in. It always helps to listen to as many error conditions as possible instead of just assuming that something worked. Especially when using external modules and functionality. Make sure that Black Box claims things are scrumdilly-umptious.
 
So,should I replace that code line
Code:
print $ua->request($req)->as_string;

with that one?
Code:
my $response = $ua->request($req);
if ($response->is_success) {
    print $response->content;  # or whatever
} else {
    die $response->status_line;
}

Also, would that synthax work as cgi script?

Thanks for the support.


 
OK.
As regard the output your code works fine on localhost but only a blank page appears if I request an url over the internet...
Still,no data was added to the form...

Here is also the form code
Code:
<form name="create" method=post action="$scriptname?createpages">
<input type=hidden name="pass" value="$fields{'pass'}">
<input type=hidden name="checkdata" value="1">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top