<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> 在tplink上刷了openwrt固件, 在上面编写了cgi测试程序</span>
示例如下:
#include <stdio.h>
#include "socket/Net.h"
// test user name and password
int Login(char* sJrmAddr,int nJrmPort,char* sUserNmae,char* sUserPwd);
int main()
{
printf("Content-type: text/html\n\n");
printf("<html> <head>\n");
printf("<title>login result</title>\n");
printf("</head>\n\n");
printf("<body>\n");
char sUserName[32]={0};
char sUserPwd[32]={0};
char* data = getenv("QUERY_STRING");
int nScanfRet=sscanf(data,"username=%[^&]&userpwd=%s",sUserName,sUserPwd);
if(nScanfRet!=2)
{
printf("<script>alert('please input username and password');window.location.href='../login.html'</script>\n");
return 0;
}
printf("</body> </html>\n");
return 0;
}
html 登录页面 如下
<html>
<head>
<title>jbox login</title>
</head>
<body bgcolor="gray" style="color:white">
<h1 align="center" style="margin-top:200px;">jbox login </h1>
<table align="center" >
<tr><td>
<form method="GET" action="./cgi-bin/jbox-cgi.cgi">
username: <input style="width:200px;height:20px;" type="txt" size="3" name="username"><br><br>
password: <input style="width:200px;height:20px;" type="password" size="3" name="userpwd"><br><br>
<input style="margin-left:100px;width:100px;height:30px;" type="submit" value="login">
</form>
</td></tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
示例下载地址: http://download.csdn.net/detail/mtour/8243601