Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > move information from HTTP::Request to CGI.pm

Reply
Thread Tools

move information from HTTP::Request to CGI.pm

 
 
Miroslav Suchy
Guest
Posts: n/a
 
      08-17-2005
Hello,
I have following code:

my $daemon = HTTP:aemon->new(
ReuseAddr => 1,
LocalAddr => 'mydomain.com',
LocalPort => 8888,
) or die "Cannot start daemon: $!\n";
while (my $conn = $daemon->accept()) {
while (my $req = $conn->get_request()) {
if ($req->method() eq 'GET') { # I do not use GET
$q = CGI->new($url->query());
} elsif ($req->method() eq 'POST') { # I only use POST method
$q = CGI->new($req->content);
open FF, ">/tmp/debug"; #output to FF just for debug
print FF $req->content;
close FF;
}
print STDERR "params: ", join(',', $q->param), "\n";
}
}

And it does not work as I expect. This is content of file "/tmp/debug":
-----------------------------18004688081790386843384315354
Content-Disposition: form-data; name="id"

6
-----------------------------18004688081790386843384315354
Content-Disposition: form-data; name="pw"

aa
-----------------------------18004688081790386843384315354--

I expect following output from script:
params: id,pw
but I get this output:
params: -----------------------------18004688081790386843384315354
Content-Disposition: form-data, name

What I'm doing wrong? Thank you.

Miroslav Suchy
 
Reply With Quote
 
 
 
 
Miroslav Suchy
Guest
Posts: n/a
 
      08-25-2005
Hello again,
I was hard working on my problem (I've HTTP::Request and I to move its
iformation to CGI object) and I come to the smallest code. But it still does not
work and I do not know where can be a problem.

8<--cut
#!/usr/bin/perl
use strict;
use HTTP:aemon ();
use CGI ();

my $daemon = HTTP:aemon->new(
LocalAddr => 'my.domain.com',
LocalPort => 8888,
) or die "Cannot start daemon: $!\n";
my $i;
while (my $conn = $daemon->accept()) {
while (my $req = $conn->get_request()) {
my $url = $req->uri();
$ENV{'REQUEST_METHOD'}=$req->method();
$ENV{'CONTENT_TYPE'}=$req->header('Content-Type');
$ENV{'CONTENT_LENGTH'}=$req->header('Content-Length');
my $filename="/dev/shm/tmp.$$.".++$i;
print STDERR "$filename\n";
open INPUT, ">$filename" or die; # prepare stdin for CGI.pm
binmode INPUT;
print INPUT $req->content;
close INPUT;
open STDIN, "<$filename" or die; # redirect stdin
my $q = CGI->new;
my $id=$q->param('id');
my $ff=$q->param('file');
print STDERR "$id-$ff----\n";
my $res = HTTP::Response->new();
$res->header('Content-Type'=> 'text/html');
my $content=$q->start_html.$q->end_html;
$res->content_length(length($content));
$res->content($content);
$conn->send_response($res);
close STDIN;
}
$conn->close();
}
8<---cut

In first while loop is everything correct. But second and all additional loops
have the same content of $q as in first loop!!!!
STDERR look like this:
/dev/shm/tmp.18353.1
4159616-4159616.jpg----
/dev/shm/tmp.18353.2
4159616-4159616.jpg----
/dev/shm/tmp.18353.3
4159616-4159616.jpg----

It means $q->param('id') returns id from the first file, which contain:
$ head -n5 /dev/shm/tmp.18353.1
--xYzZY
Content-Disposition: form-data; name="id"

4159616
--xYzZY
but it should return id from the second file, which contain:
$ head -n5 /dev/shm/tmp.18353.2
--xYzZY
Content-Disposition: form-data; name="id"

4159620
--xYzZY

If I try to dump STDIN after the line:
open STDIN, "<$filename" or die; # redirect stdin
it is the same as content of file $filename
But CGI module somehow remember its state from first reading!!
How can I force CGI to re-read STDIN?
Or make I something wrong?

BTW: The request for this daemon is created using this code:
....
my $ua = LWP::UserAgent->new;
my $response = $ua->post('http://my.domain.com:8888/',
[
id => $id,
file => ["$path$id.jpg"] ,
],
'Content_Type' => 'form-data',
);

Thanks in advance for any suggestion

Miroslav Suchy




 
Reply With Quote
 
 
 
 
Miroslav Suchy
Guest
Posts: n/a
 
      08-25-2005
Hello again,
I solved my problem. For archive purpose:
If you want to read STDIN again with CGI you must undef @CGI::QUERY_PARAM (Yeah,
that one with comment "Other globals that you shouldn't worry about." in CGI.pm )

Miroslav Suchy
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing move constructors and move assignment Andrew Tomazos C++ 2 12-12-2011 01:45 PM
More Information than just IIS Log Information subrato ASP .Net 8 03-14-2006 09:59 PM
I am trying to move spaces to a weblistbox and when I move them... Eduardo78 ASP .Net Web Controls 0 11-03-2005 06:06 PM
strange information from asp.net trace / getting performance information using WebRequest and StreamReader z. f. ASP .Net 0 02-03-2005 11:23 AM
Sigma SD10 Information Page--Web Site Move Steven M. Scharf Digital Photography 18 05-16-2004 07:03 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57