平时下班等女朋友总是要等很长时间,想看书又没有带,只有玩手机游戏;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"?> ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
用手机试一下,OK
现在写小说的WAP程序。
先从网上下一篇小说,存在目录下,1.txt
不过小说太大了,必须先要有一个目录,按2K分页吧,好家伙,有200页,算了,来一个直接选页数的GO吧:
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
所有的代码:
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"?> ";
// WapContent="<?xml version="1.0" encoding="gb2312"?> ";
WapContent+=" ";
WapContent+=" ";
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+=" ";
int k=mC.Length/3000;
WapContent+="
WapContent+="
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
return;
}
else
n=System.Convert.ToInt32(Request["Page"]);
WapContent="<?xml version="1.0"?> ";
WapContent+=" ";
WapContent+=" ";
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(" ","
");
ArtMore=true;
}
//每屏3000字
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
//选取页面
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
}
拿起手机,www.tjkx.com/wap.aspx,试一下,爽!!!
用手机调试太麻烦,下载一个WinWap Pro3.1在这里面调试。
工具齐备了,看来C#真好,写个小程序就这样简单
都说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"?> ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="
hello老婆
";WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
用手机试一下,OK
现在写小说的WAP程序。
先从网上下一篇小说,存在目录下,1.txt
不过小说太大了,必须先要有一个目录,按2K分页吧,好家伙,有200页,算了,来一个直接选页数的GO吧:
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
所有的代码:
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"?> ";
// WapContent="<?xml version="1.0" encoding="gb2312"?> ";
WapContent+=" ";
WapContent+=" ";
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+=" ";
int k=mC.Length/3000;
WapContent+="
目录
";WapContent+="
共:"+k.ToString()+"页
";WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
return;
}
else
n=System.Convert.ToInt32(Request["Page"]);
WapContent="<?xml version="1.0"?> ";
WapContent+=" ";
WapContent+=" ";
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(" ","
");
ArtMore=true;
}
//每屏3000字
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="
";
WapContent+=n.ToString()+"P";
WapContent+=mC;
WapContent+="
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
//选取页面
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+="就看这页!
";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
WapContent+=" ";
Response.Write(WapContent);
}
拿起手机,www.tjkx.com/wap.aspx,试一下,爽!!!
用手机调试太麻烦,下载一个WinWap Pro3.1在这里面调试。
工具齐备了,看来C#真好,写个小程序就这样简单
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-125329/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10294527/viewspace-125329/