- 論壇徽章:
- 0
|
CGI問題,高手指教.502 Bad Gateway
我在開發(fā)板上移植好boa后.
測(cè)試 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
但測(cè)試另一個(gè)程序后,出現(xiàn)以下錯(cuò)誤:
502 Bad Gateway
The CGI was not CGI/1.1 compliant.
我的網(wǎng)頁代碼:
<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>
單擊確定后:網(wǎng)址為:http://192.168.1.5/cgi-bin/test_led.cgi?no=1&status=0
測(cè)試程序:
#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;
}
請(qǐng)問是不是我編寫的CGI程序有問題?還是我只編寫了一個(gè)網(wǎng)頁的原因?請(qǐng)高手指教,還是我傳遞參數(shù)錯(cuò)誤?十萬火急! |
|