result in headers trace as follows#!/usr/bin/perl use strict; use warnings; use HTTP::Response; my $respbody = '<root/>'; my $response; $response = HTTP::Response->new('200','Ok'); $response->header( 'Content-type' => 'application/xml' ); $response->header( 'Cache-control' => 'no-cache, must-revalidate' ); $response->header( 'Content-length' => length($respbody) ); $response->content($respbody); print $response->as_string; 1; __END__
and the actual content (re: using lighttpd)http://localhost/tia/signage/edit/myresp.pl GET /tia/signage/edit/myresp.pl HTTP/1.1 Host: localhost User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Firef +ox/45.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0. +8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive HTTP/1.1 200 OK Content-Length: 105 Date: Sun, 08 Jan 2017 23:08:16 GMT Server: lighttpd
If I use print statements as in the following, all is ok.200 OK Cache-Control: no-cache, must-revalidate Content-Length: 7 Content-Type: application/xml <root/>
It appears to me that the HTTP:Response object, when using method '->as_string', does not send [at least] the correct formatted status line. Can the HTTP::Response object be used directly in a server cgi script and if so, how should I use it to get it to work as expected... in this test case, to show the simple xml in the browser (which it does if I use just the print statements as shown).#!/usr/bin/perl use strict; use warnings; print "Status: 200\n"; print "Content-Type: application/xml\n\n"; print "<root/>\n"; 1; __END__
Thank you for any insight.
Habs
In reply to using HTTP::Response directly by Habs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |