- 论坛徽章:
- 0
|
我在开发板上移植好boa后,想测试CGI程序.
我的CGI程序:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#define IOCTL_LED_ON 0
#define IOCTL_LED_OFF 1
#define MAX_ARG 150
int main(void)
{
unsigned int led_no;
int fd = -1;
char *buf = getenv("QUERY_STRING");
if (buf == NULL)
return -1;
char para1[MAX_ARG], para2[MAX_ARG];
char value1[MAX_ARG], value2[MAX_ARG];
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)
{
return -1;
}
if ((num - 1) > 3)
{
goto err;
}
ioctl(fd, status, num);
close(fd);
return 0;
err:
if (fd > 0)
close(fd);
return -1;
}
我网页中的 form
<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/led">
<h2>Input led number: </h2>
NO.: <input type=text name=no> <br>
<h3>(Notice!! the number is: 1-6) </h3> <br>
Status: <input type=text name=status>
<h3>Notice!!(1: on, 0: off) </h3> <br>
<p align="center"> <input type=submit value=" 确定">
</form>
<p align="center">
</body>
</html>
提交数据后, 参数应该是 "no=xx&status=xxx"
我在CGI程序中,用getenv("QUERY_STRING");获取参数,不知这样做对不对?
结果网页提交数据后出现以下错误:
502 Bad Gateway
The CGI was not CGI/1.1 compliant.
我CGI的makefile
CC = /usr/local/arm/3.4.1/bin/arm-linux-gcc
test_led : test_led.c
$(CC) test_led.c -o test_led
请问我这样做对不对,不对该怎么样改,才能通过网页传递参数给CGI程序? |
|