首页 > 开发 > 综合 > 正文

C#开发WAP程序

2024-07-21 02:18:18
字体:
来源:转载
供稿:网友
平时下班等女朋友总是要等很长时间,想看书又没有带,只有玩手机游戏;gprs上网,好象很多内容都是要付费的,就只有下载铃声,什么图片的,没劲!最好能用手机看看小说,网络上好象没有免费的wap小说,办公室的小妹妹也想用手机看小说,看来只有自己做一个了。
都说java是开发wap的利器,不过wap需要这个“码”转到那个“码”,真是麻烦,算了,看一下能不能用c#做一个wap小站。
想来也很简单的,wap就是用utf8编码嘛,好象还有什么wml之类的,wml在网上查查资料,就和xml差不多,平时用xml也蛮多的,wml也就简单了,c#直接可以设response的编码的,看来有戏了,先写一个“hello 老婆“吧,
//设置contenttype类型
response.contenttype="text/vnd.wap.wml";
//设置编码
response.contentencoding=system.text.encoding.utf8;
//以下是根据wml协议写的内容部份
wapcontent="<?xml version=/"1.0/" encoding=/"utf8/"?>/r/n";
wapcontent+="<!doctype wml public /"-//wapforum//dtd wml 1.1//en/" /"http://www.wapforum.org/dtd/wml_1.1.xml/"><wml>/r/n";
wapcontent+="/r/n";
wapcontent+="<card id=/"hello/">/r/n";
wapcontent+=" <p>hello老婆 </p>/r/n";
wapcontent+="</card>/r/n";
wapcontent+="/r/n";
wapcontent+="</wml>/r/n";
wapcontent+="/r/n";
response.write(wapcontent);
用手机试一下,ok
现在写小说的wap程序。
先从网上下一篇小说,存在目录下,1.txt
不过小说太大了,必须先要有一个目录,按2k分页吧,好家伙,有200页,算了,来一个直接选页数的go吧:
wapcontent+=" <input name=/"pagenum/" size=/"3/" maxlength=/"10/" type=/"text/" format=/"*n/" emptyok=/"true/"/>";
wapcontent+="<anchor title=/"login/">/n";
wapcontent+="<go href=/"wap.aspx/" method=/"get/">/n";
wapcontent+="<postfield name=/"page/" value=/"$pagenum/"/>/n";
wapcontent+="</go>就看这页!<br/>/n";
wapcontent+="</anchor>/n";
所有的代码:
private void page_load(object sender, system.eventargs e)
{
string wapcontent;
string mc;
//在调试时用gb2312模拟器
response.contenttype="text/vnd.wap.wml";
// response.contenttype="text/vnd.wap.wml;charset=utf-8";
response.contentencoding=system.text.encoding.utf8;// unicode ;// "utf8";
// response.contentencoding=system.text.encoding.getencoding("gb2312");
int n=0;
if(request["page"]==null)
{
//显示目录
wapcontent="<?xml version=/"1.0/" encoding=/"utf8/"?>/r/n";
// wapcontent="<?xml version=/"1.0/" encoding=/"gb2312/"?>/r/n";
wapcontent+="<!doctype wml public /"-//wapforum//dtd wml 1.1//en/" /"http://www.wapforum.org/dtd/wml_1.1.xml/"><wml>/r/n";

wapcontent+="/r/n";
system.io.fileinfo ofm=new system.io.fileinfo(request.physicalpath);
system.io.streamreader oreaderd=new system.io.streamreader(ofm.directoryname +"//"+ "1.txt",system.text.encoding.default);
//每次读3000字

mc=oreaderd.readtoend() ;
oreaderd.close();
wapcontent+="<card id=/"lists"+n.tostring()+"/">/r/n";

int k=mc.length/3000;
wapcontent+=" <p>目录</p>/r/n";
wapcontent+=" <p>共:"+k.tostring()+"页</p>/r/n";

wapcontent+=" <input name=/"sid/" size=/"3/" maxlength=/"10/" type=/"text/" format=/"*n/" emptyok=/"true/"/>";
wapcontent+="<anchor title=/"login/">/n";
wapcontent+="<go href=/"wap.aspx/" method=/"get/">/n";
wapcontent+="<postfield name=/"page/" value=/"$sid/"/>/n";
wapcontent+="</go>就看这页!<br/>/n";
wapcontent+="</anchor>/n";

wapcontent+="<onevent type=/"onenterbackward/">/r/n";
wapcontent+=" <prev/>/r/n";
wapcontent+=" </onevent>/r/n";



wapcontent+="</card>/r/n";



wapcontent+="/r/n";



wapcontent+="</wml>/r/n";
wapcontent+="/r/n";
response.write(wapcontent);
return;

}
else
n=system.convert.toint32(request["page"]);


wapcontent="<?xml version=/"1.0/"?>/r/n";
wapcontent+="<!doctype wml public /"-//wapforum//dtd wml 1.1//en/" /"http://www.wapforum.org/dtd/wml_1.1.xml/"><wml>/r/n";

wapcontent+="/r/n";
system.io.fileinfo of=new system.io.fileinfo(request.physicalpath);
system.io.streamreader oreader=new system.io.streamreader(of.directoryname +"//"+ "1.txt",system.text.encoding.default);
//每次讯读3000字

mc=oreader.readtoend() ;
oreader.close();
if(mc.length>4000)
{
mc=mc.substring((n)*3000,3000);
mc=mc.replace("/r/n","<br/>");
artmore=true;
}

//每屏3000字


wapcontent+="<card id=/"lists"+n.tostring()+"/">/r/n";

wapcontent+=" <do type=/"accept/" label=/""+(n-1).tostring()+"/">/r/n";
wapcontent+=" <go href=/"wap.aspx?page="+(n-1).tostring()+"/"/>/r/n";
wapcontent+=" </do>/r/n";
wapcontent+="<onevent type=/"onenterbackward/">/r/n";
wapcontent+=" <prev/>/r/n";
wapcontent+=" </onevent>/r/n";

wapcontent+=" <p>/r/n";
wapcontent+=n.tostring()+"p";

wapcontent+=mc;


wapcontent+=" </p>/r/n";

wapcontent+=" <do type=/"accept/" label=/"下一页/">/r/n";
wapcontent+=" <go href=/"wap.aspx?page="+(n+1).tostring()+"/"/>/r/n";
wapcontent+=" </do>/n";
//选取页面
wapcontent+=" <input name=/"sid/" size=/"3/" maxlength=/"10/" type=/"text/" format=/"*n/" emptyok=/"true/"/>";
wapcontent+="<anchor title=/"login/">/n";
wapcontent+="<go href=/"wap.aspx/" method=/"get/">/n";
wapcontent+="<postfield name=/"page/" value=/"$sid/"/>/n";
wapcontent+="</go>就看这页!<br/>/n";
wapcontent+="</anchor>/n";
wapcontent+="</card>/r/n";



wapcontent+="/r/n";



wapcontent+="</wml>/r/n";
wapcontent+="/r/n";
response.write(wapcontent);




}
拿起手机,www.tjkx.com/wap.aspx,试一下,爽!!!
用手机调试太麻烦,下载一个winwap pro3.1在这里面调试。
工具齐备了,看来c#真好,写个小程序就这样简单


中国最大的web开发资源网站及技术社区,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表