You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Robert Andersson <ro...@profundis.nu> on 2003/06/12 06:09:30 UTC

Re: [users@httpd] Premature end of script headers

In ancient times (April 26, 2003 ;-) Gabriel wrote:

> Hi,
>
> I'm tring to run my first CGI in C language. Of course it's Hello World.
> The code is that:
>
> #include <stdio.h>
>
> int main()
> {
> printf("Content-type: text/html\n\n");
> printf("<HTML>\n");
> printf("<BODY>\n");
> printf("<CENTER><H1>HELLO WORLD</H1></CENTER>\n");
> printf("</BODY>\n");
> printf("</HTML>");
>
> return 0;
> }
>
> when I try to run it the browser shows INTERNAL SERVER ERROR
> And the error log file shows Premature end of script headers

I doubt that Gabriel is still on this, but I saw no reply that commented on
what struck me first, so for the archives sake.

The problem is likely the new-lines. "\n" compiles to ASCII 10 = 0x0a. But,
the HTTP protocol defines new-line as <CRLF> => ASCII 13 + 10 = 0x0d + 0x0a.

Therefor, the first line should be:

    printf("Content-type: test/html\r\n\r\n");


Regards,
Robert Andersson


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org