I am trying to write a CGI Program which is invoked from a HTML page . The CGI code snippet is as follows:

 echo "Content-type: text/html"
 echo  "<html>"
 echo "<body>"
 echo "Hi"
 echo "</body>"
 echo "</html>"

But after executing the script I can see the 500:Internal Server Error in browser page. .

Following can be seen in error log file

[Wed Apr 09 18:36:59 2014] [error] [client] malformed header   
from script. Bad header=<html>: image.sh
[Wed Apr 09 18:37:14 2014] [error] [client] malformed header 
from script. Bad header=<html>: image.sh
  • Are you sure your script is executed ? could you show use some config of your webserver ?
    – Kiwy
    Apr 9, 2014 at 8:12

1 Answer 1


As the HTTP spec (and the error message from your HTTP server) specify, you need one blank line between the HTTP headers and the body, otherwise the server doesn't know where the headers end and the body begins. From RFC 2616 (emphasis my own):

Request (section 5) and Response (section 6) messages use the generic message format of RFC 822 [9] for transferring entities (the payload of the message). Both types of message consist of a start-line, zero or more header fields (also known as "headers"), an empty line (i.e., a line with nothing preceding the CRLF) indicating the end of the header fields, and possibly a message-body.

To fix the problem, put another echo before echo "<html>", so that the headers are clearly separated from the body.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .