我正在使用这个 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;
}
我编译它使用
gcc script.c -o script.fcgi -lfcgi -O3 -Wall -Wextra -pedantic -std=c11
然后,我输入终端:
cgi-fcgi -start -connect localhost:9000 script.fcgi
cgi-fcgi -connect localhost:9000 script.fcgi
并获得输出
Status: 200 OK
Content-type: text/html
<!doctype><html><body>Welcome!</body></html>
之后,我使用了 curl
curl localhost:9000
curl: (52) Empty reply from server
和远程登录
telnet localhost 9000
Connected to localhost.
GET / HTTP/1.1
Connection closed by foreign host.
为什么我只使用 cgi-fcgi 获得成功结果?如何使用 curl 和 telnet 从脚本中获取相同的数据?