当前位置: 代码迷 >> CGI >> 请高人指导CGI有关问题
  详细解决方案

请高人指导CGI有关问题

热度:344   发布时间:2012-04-09 13:41:25.0
请高人指导CGI问题
我使用BOA做嵌入式web开发,用C写的程序,如果将网页内容完全用printf()出来,在web中打开没任何问题,但是因为html网页内容较多,我采用fgetc()/fgets()将文件内容读出,然后printf()或puts(),但是在web中总是提示“502 Bad Gateway The CGI was not CGI/1.1 compliant. ”错误。但是在Linux下运行,两者打印的内容完全一致。
  具体程序如下:


------解决方案--------------------
Contenttype ? Content-type吧
------解决方案--------------------
你的文件头输出的是printf("Contenttype:text/plain\n\n"); text/plain按照文本形式输出,
读出来的内容是html的
把你source改成这样看看吧。
把输出的header部分修改一下,我想是应该可以的。
printf("Content-type: text/html\n\n");

------解决方案--------------------
刚才查了一下,有可能是Linux下面和Windows下面换行符不同造成的。
有可能你是在win环境下面编辑的,然后扔到Linux上面执行,但是换行符不同,造成的。

论坛里面的讨论如下:
--------------------------------
502 Bad Gateway
The CGI was not CGI/1.1 compliant.

If you obtain this message probably you have used a "DOS like" editor like Notepad to edit the helloworld.sh script file. This add a CR/LF sequence at the end of each lines instead of a single LF. If you are using UltraEdit or any other good editor probably you can choose to save the file in Unix format elsewhere use these commands to strip the CR chars:

# cat helloworld.sh | tr -d '\r' > helloworld1.sh
# cp helloworld1.sh helloworld.sh
  相关解决方案