Chinaunix首页 | 论坛 | 博客
  • 博客访问: 448936
  • 博文数量: 62
  • 博客积分: 1312
  • 博客等级: 中尉
  • 技术积分: 1555
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 18:10
文章分类

全部博文(62)

文章存档

2014年(1)

2013年(5)

2012年(56)

分类: LINUX

2012-05-21 18:04:44

在做嵌入式WEB服务器的时候出现下面这个问题:
 
通过浏览器登录服务器是浏览器页面显示下面信息:
    502 Bad Gateway  

    The CGI was not CGI/1.1 compliant.
 
终端错误输出为:
[31/Dec/1999:18:27:05 +0000] cgi_header: unable to find LFLF
cgi的程序源文件login.c为:

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. int main(void)
  4. {
  5.     char *str_len=NULL;
  6.     int len=0;
  7.     char buf[100]="";    
  8.     char user[20]="";
  9.     char passwd[20]="";
  10.     
  11.     printf("%s\n\n","Content-Type:text/html");
  12.     printf("\n\nCGI3:登录结果
    \n"
    );
  13.     str_len = getenv("CONTENT_LENGTH");    
  14.     if( (str_len==NULL) || (sscanf(str_len, "%d", &len)!=1) || (len>80) )
  15.         printf("sorry!error!");
  16.     fgets(buf, len+1, stdin);
  17.     sscanf(buf, "name=%[^&]&password=%s", user,passwd);
  18.     if( (strncmp(user,"root",4)==0) && (strncmp(passwd, "111111", 6)==0) )
  19.     {
  20.         printf("");
  21.     }
  22.         
  23.     else
  24.         printf("

    Sorry! 用户名或密码错误!");

  25.     return 0;
  26. }

出现这个错误的原因就在于上面程序的第12行中漏掉了输出字符串结束时的两个换行。这两个换行必须要。而且一定要写成:


 

点击(此处)折叠或打开

  1. printf("%s\n\n","Content-Type:text/html");


 

阅读(3645) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~