I am using this script.c:
#include <fcgi_stdio.h>
#include <stdlib.h>
int main (void) {
while (FCGI_Accept() >= 0) {
printf("Status: 200 OK\r\n");
printf("Content-type: text/html\r\n\r\n");
printf("<!doctype><html><body>Welcome!</body></html>\n");
}
return EXIT_SUCCESS;
}
I compile it using
gcc script.c -o script.fcgi -lfcgi -O3 -Wall -Wextra -pedantic -std=c11
Then, I put in terminal:
cgi-fcgi -start -connect localhost:9000 script.fcgi
cgi-fcgi -connect localhost:9000 script.fcgi
and get output
Status: 200 OK
Content-type: text/html
<!doctype><html><body>Welcome!</body></html>
After that, I used curl
curl localhost:9000
curl: (52) Empty reply from server
and telnet
telnet localhost 9000
Connected to localhost.
GET / HTTP/1.1
Connection closed by foreign host.
Why I got success result with cgi-fcgi only? How to use curl and telnet to obtain the same data from script?