tags:

views:

298

answers:

1

Hi,

I am running Apache server. When I send the request from HTML using ajax call to cgi, I am not getting any response.

I found the following error statement in the httpd/error_log file: Premature end of script headers: file.cgi

When I gave alert to the status code, it returned 500 Internal Server Error.

How to resolve this?

+1  A: 

You're not returning a full set of headers. The output for a CGI must be of the format:

[header]
[blankline]
[body]

If you're getting the "Premature end..." error, the most likely reason is that you're not supplying any header. At an absolute bare minimum, you should return the content-type and then any other optional fields, for example, a simple "Hello world" response would be:

Content-type: text/plain

Hello world!

Or a simple HTML example:

Content-type: text/html

<html>
<body>Hello world!</body>
</html>

Other headers you may want to return with Content-type include those that control the cache, cookies, redirects, etc.

Chris J
Thank you, I got it working...I have to use printf("Content-type: text/html; charset=utf-8\n\n");instead of printf("%s%c%c\n\n","Content-Type:text/html;charset=iso-8859-1",13,10);
MalarN