Hi all, Suzzane, just add following after SheBang line
print "Content-Type: text/html\n\n"; and your script will run fine. I have tested your code over Aapche (Win98). regards, -Ahmed. On 1 Oct 2002 at 12:09, Suzanne J Dimant wrote: > This post is in response to [EMAIL PROTECTED]'s "two forms" post on > Tue, 24 Sep 2002, and also intended to open up general brainstorming about > the "malformed headers" error reported in that post: > > Like Ahmed, I am also receiving a "malformed headers" error as a result of a > LWP GET request by a CGI script for an HTML page. I sometimes get a > "Premature end of script headers" error as well. However, when I execute the > CGI script via telnet on port 80 I can see what seem to be intact headers. > When I run the script from the command prompt it does in fact return all the > HTML it requests, and I confirmed by writing debug statement to STDERR that > my script runs past the handoff of the request to the UserAgent when invoked > via a browser. > > The most notable similarity between my headers and Ahmed's is the > "Connection: Close" header... so I was wondering if the problem is that the > connection is closing before the request is complete. I therefore > experimented a bit with the timeout and connection-cache UserAgent > properties but that didn't seem to help. (Actually, my script was having > trouble finding ConnCache.pm even though it was in my specified lib path, > but I created the UserAgent object with the connection attribute set to > 'keepalive' which should suffice?) > > I found a report by someone developing in a shared website environment that > suggests LWP could malfunction in an environment where socket permissions > are restricted: http://cgi-help.virtualave.net/. I am on a shared Sun > Solaris webserver (OS 5.8) running Apache/1.3.12; Ahmed: are you on a shared > webserver as well? > > I considered the possibility that certain servers require explicit > specification of the charset in the Content-type header (as per > http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 ) but that > didn't seem to help either. I also considered the possibility that the > server is requiring a specific sequence of headers, but I requested a simple > page via telnet on port 80 to discover that the server simply returned the > http-version/status, server, date and content-type headers; that's all! So I > made sure to send exactly those headers, in that exact order, to no remedy. > I considered that there might be some header negotiation going on that I > can't discern simply by telneting on port 80, so I tried to install a local > verion of tcpdump but I didn't seem to be able to configure and install it > properly with my limited permissions. > > Phew! Any ideas anyone? Should I give up running LWP in this shared > webserver environment? > > Below is my code, > Suzanne Dimant > > ======== http://www.dimantdomain.com/cgi-bin/request3.cgi > =================== > > #!/bin/perl5 > > use lib > "/home/dimant/wwwsite-dimantdomain.com/lib/lib/site_perl/5.6.0/sun4-solaris/ > , /home/dimant/wwwsite-dimantdomain.com/lib/lib/site_perl/5.6.0/"; > > use LWP; > #can't find ConnCache.pm even tho it's in the LWP folder under lib path > #use LWP::ConnCache; > print STDERR "line 9: lines 1-8 OK - "; > # Create a user agent object > my $ua = LWP::UserAgent->new( > env_proxy => 1, > keep_alive => 1, > timeout => 60, > agent => "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; AT&T CSM6.0)" > ); > > #can't find ConnCache.pm even tho it's in the LWP folder under lib path > #$cache = new LWP::ConnCache; > #$ua->conn_cache($cache); > > # Create a request > $req = HTTP::Request->new(GET => > 'http://www.dimantdomain.com/perlprogs.html'); > $req->date('Tue, 01 Oct 2002 11:59:00 GMT'); > $req->server('Apache/1.3.12 (Unix) ApacheJServ/1.1 PHP/4.0.3pl1 > PHP/3.0.14'); > #$req->header('Accept' => 'text/html'); # send request > $req->content_type('text/html; charset=ISO-8859-4'); > print STDERR "line 21: lines 10-20 OK - "; > # Pass request to the user agent and get a response back > my $res = $ua->request($req); > print STDERR "line 24: lines 22-23 OK - "; > # Check the outcome of the response > if ($res->is_success) { > print $res->content; > #to print headers to STDOUT: > #print $req->as_string; > } else { > print "Error: " . $res->status_line . "\n"; > } > ===================== end request3.cgi ============== > >
