我在开发板上移植好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;
}
但测试另一个程序后,出现以下错误:
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&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-bin目录
chmod 755 *