5.4 测试webs服务器
用FTP把webs执行文件传到目标板中,本人把其放到了/mnt/webs/目录中。
需要注意的是,在goAhead2.5版本中,web网页的根目录是在webs程序的../www或../wwwdemo(webs执行时带-demo参数)中,这一点可查看LINUX/main.c文件中190行处代码和注释。因此,把goAhead源码目录下的www和wwwdemo两文件夹传用FTP传到/mnt/目录下。
在PC机用IE浏览器浏览goAhead服务器的网页,输入http://192.168.1.168:8080/
192.168.1.168是目标板的IP地址即goAhead服务器的地址,8080是goAhead用的端口号,这是默认的端口号,定义在webs.h文件。
5.4.1 测试问题
用浏览器死活不管怎样,都打不开home.htm网页的,提示是404错误,意思是:
Access Error: Site or Page Not Found
Cannot open URL
5.4.2 不能打开网页的原因和解决方法
折腾许久,决定从源代码着手。最后定位在default.c文件中websDefaultHandler()函数中,这个函数是处理默认网页的。
具体代码段如下:
- /*
- * We do whitelist validation in addition to standard URL validation.
- * The whitelist should really catch anything invalid first.
- * If the whitelist check fails, rebuild the list and try again.
- * Also validate if we are not on a secure connection, but the whitelist
- * entry has the SSL flag set, do not serve the page.
- */
- #ifdef WEBS_WHITELIST_SUPPORT
- if ((rc = websWhitelistCheck(wp->url)) < 0) {
- websBuildWhitelist();
- if ((rc = websWhitelistCheck(wp->url)) < 0) {
- websError(wp, 404, T("Cannot open URL"));
- return 1;
- }
- }
- if (!(flags & WEBS_SECURE) && (rc & WHITELIST_SSL)) {
- websError(wp, 500, T("HTTPS access required"));
- return 1;
- }
- #endif /* WEBS_WHITELIST_SUPPORT */
问题就出现在上面这个代码中,我的理解是goAhead关于网页安全方面功能,即网页白名单(WHITELIST)功能支持。
把宏WEBS_WHITELIST_SUPPORT关闭,重新编译,再测试,OK了,可以打开网页了。
上述只是简单的移植测试,然我们最终的目的是要把goAhead移植到我们的应用程序中的,在大多数的应用中,它也只是应用程序中的一个模块,因此,后面的工作量还是蛮多的,包括SSL的移植等等。
