Http Response code

Http Response code

am 24.08.2007 01:21:26 von mohitanchlia

Is there any way we can successfully tell web server to use the error
code that we set in response object. I am doing this below when cgi is
called, expecting web server to send 503 as response code instead of
200:

#!/usr/bin/perl
require HTTP::Response;
require LWP::UserAgent;

$response = HTTP::Response->new(503) ;
$response->header('Content-Type' => 'text/plain');
$response->header('Content-length' => '5');
$response->content("Error");
print $response->as_string;

But, webserver doesn't like it. It's writing invalid cgi header errors
to the logs. How do I change the response codes ?

Re: Http Response code

am 24.08.2007 01:48:16 von Jim Gibson

In article <1187911286.776265.279700@x40g2000prg.googlegroups.com>,
wrote:

> Is there any way we can successfully tell web server to use the error
> code that we set in response object. I am doing this below when cgi is
> called, expecting web server to send 503 as response code instead of
> 200:
>
> #!/usr/bin/perl
> require HTTP::Response;
> require LWP::UserAgent;
>
> $response = HTTP::Response->new(503) ;
> $response->header('Content-Type' => 'text/plain');
> $response->header('Content-length' => '5');
> $response->content("Error");
> print $response->as_string;
>
> But, webserver doesn't like it. It's writing invalid cgi header errors
> to the logs. How do I change the response codes ?
>

HTTP::Response (and LWP::UserAgent) are for client-side programs
pretending to be browsers. For CGI, you want to use the CGI module and
return an appropriate header, e.g.

use CGI;
print header('text/html','503 Service unavailable');


See 'perldoc CGI' and search for 'STANDARD HTTP HEADER'.

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Re: Http Response code

am 24.08.2007 06:01:08 von mohitanchlia

On Aug 23, 4:48 pm, Jim Gibson wrote:
> In article <1187911286.776265.279...@x40g2000prg.googlegroups.com>,
>
>
>
> wrote:
> > Is there any way we can successfully tell web server to use the error
> > code that we set in response object. I am doing this below when cgi is
> > called, expecting web server to send 503 as response code instead of
> > 200:
>
> > #!/usr/bin/perl
> > require HTTP::Response;
> > require LWP::UserAgent;
>
> > $response = HTTP::Response->new(503) ;
> > $response->header('Content-Type' => 'text/plain');
> > $response->header('Content-length' => '5');
> > $response->content("Error");
> > print $response->as_string;
>
> > But, webserver doesn't like it. It's writing invalid cgi header errors
> > to the logs. How do I change the response codes ?
>
> HTTP::Response (and LWP::UserAgent) are for client-side programs
> pretending to be browsers. For CGI, you want to use the CGI module and
> return an appropriate header, e.g.
>
> use CGI;
> print header('text/html','503 Service unavailable');
>
> See 'perldoc CGI' and search for 'STANDARD HTTP HEADER'.
>
> --
> Jim Gibson
>
> Posted Via Usenet.com Premium Usenet Newsgroup Services
> ----------------------------------------------------------
> ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
> ----------------------------------------------------------
> http://www.usenet.com

I read little bit about it and saw there is something called as -
status. So what's the difference between:

print header('text/html','204 No response');

and

print header(-status=>cgi_error);

Both seem to be returning error codes

Re: Http Response code

am 24.08.2007 18:47:03 von Jim Gibson

In article <1187928068.424378.215060@i13g2000prf.googlegroups.com>,
wrote:


>
> I read little bit about it and saw there is something called as -
> status. So what's the difference between:
>
> print header('text/html','204 No response');
>
> and
>
> print header(-status=>cgi_error);
>
> Both seem to be returning error codes
>

Yes. In the first case you determine the response. In the second case,
the CGI module is determining the response.

You can also do:

print header(-status=>'204 No response');

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com