免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2079 | 回复: 1
打印 上一主题 下一主题

CGI问题,高手指教.502 Bad Gateway [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-24 10:29 |只看该作者 |倒序浏览
CGI问题,高手指教.502 Bad Gateway
我在开发板上移植好boa后.
测试 hello.cgi 成功.
#include <stdio.h>
int  main()
{

    printf("Content-type: text/html\n\n");
    printf(" <html>\n");
    printf(" <head>\n");
    printf(" <title>my page </title>\n");
    printf(" <h1>hello world </h1>");
    printf(" </head>\n");
    printf(" </HTML>\n");
  return 0;
}
http://192.168.1.5/hello.cgi 显示hello world

但测试另一个程序后,出现以下错误:
502 Bad Gateway
The CGI was not CGI/1.1 compliant.

我的网页代码:
<html>
<head> <title>LED Control </title> </head>
<body>
<h1>This is my first web program </h1>
<img align="middle" src="success.jpg">
<br>
<br>
<form method="GET" action="/cgi-bin/test_led.cgi">
<h2>Input led number: </h2>
NO.: <input type=text name=no> <br>
<h3>(Notice!! the number is: 1-4) </h3> <br>
Status: <input type=text name=status>
<h3>Notice!!(1: on, 0: off) </h3> <br>
<p align="center"> <input type=submit value="  OK">
</form>
<p align="center">
</body>
</html>

单击确定后:网址为:http://192.168.1.5/cgi-bin/test_led.cgi?no=1&amp;status=0

测试程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>

#define MAX_ARG 150

int main(void)
{

unsigned int led_no;
int fd = -1;
char para1[MAX_ARG], para2[MAX_ARG];
char value1[MAX_ARG], value2[MAX_ARG];

printf("%s%c%c ", "Content-Type:text/html", 13, 10);
printf(" <title>control result </title>");

char *buf = getenv("QUERY_STRING");
if (buf == NULL)
{
printf(" <error! there is no data!>");
return -1;
}

char *p = strchr(buf, '&');
*p = '\0';
strcpy(para1, buf);
strcpy(para2, p + 1);

p = strchr(para1, '=');
*p = '\0';
strcpy(value1, p + 1);

p = strchr(para2, '=');
*p = '\0';
strcpy(value2, p + 1);

int num, status;
num = atoi(value1);
status = atoi(value2);

fd = open("/dev/mini2440_led", 0);
if (fd < 0)
{
printf(" <p>error! open fail");
return -1;
}

if ((num - 1) > 3)
{
goto err;
}

ioctl(fd, status, num);
printf(" <p>sucess!");
close(fd);
return 0;
err:
if (fd > 0)
close(fd);
printf(" <p>data error!");
return -1;

}


请问是不是我编写的CGI程序有问题?还是我只编写了一个网页的原因?请高手指教,还是我传递参数错误?十万火急!

论坛徽章:
0
2 [报告]
发表于 2009-10-24 13:38 |只看该作者
你说你测试hello world成功,但是你没有测试hello world传入参数是否成功啊。
你先写一个能正确显示传入的参数的cgi试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP