L
L
lockdog2013-07-23 21:42:35
Apache HTTP Server
lockdog, 2013-07-23 21:42:35

Error while executing CGI script "premature end of script headers"

I ask for your help, habravchane!
I installed Apache on the machine and wrote a script in C for remote control of a home robot.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include "PortDriver.h"

int main(void)
{
    HANDLE h;
    char *query;
    query=(char*)malloc(sizeof(char)*256);
    h=InitPort("\\\\.\\COM2",57600);
    query=getenv("QUERY_STRING");

    if (h==INVALID_HANDLE_VALUE)
    {
        printf("Error\n");
        return 0;
    }

    if (strstr(query,"COMM=W")!=0)
    {
        SendData(h,'W');

    }

    if (strstr(query,"COMM=A")!=0)
    {
        SendData(h,'A');

    }

    if (strstr(query,"COMM=S")!=0)
    {
        SendData(h,'S');

    }

    if (strstr(query,"COMM=D")!=0)
    {
        SendData(h,'D');

    }

    if (strstr(query,"COMM=Q")!=0)
    {
        SendData(h,'Q');

    }
    free(query);
    printf("Status: 204 No Change\n");
    return 0;
}

A page is generated in the browser where I display video from the camera and process the keyboard. I send commands to the server with GET, the script itself processes them, but an error page arrives in response, the Apache log gives out: “premature end of script headers”.
What should be done so that after pressing a button on the keyboard and after executing the script, the page in the browser is not updated and nothing else appears?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kafeman, 2013-07-23
@lockdog

Headings must end with \r\n\r\n.
For example:

printf("Content-type:text/plain\r\n\r\n");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question