Wap中常見Asp+Wml問題
在HTML中有一個默認的E-Mail機制:" mailto:" 。但在WML中不好使,因此E-Mails必須通過WML表單來解決。例如:
<wml>
<card id="edit" title="Email Editor">
<p>From: <input type="text" name="from" format="*M"/></p>
<p>To: <input type="text" name="to" format="*M"/></p>
<p>Subject: <input type="text" name="subject" format="*M"/></p>
<p>Message body: <input type="text" name="body" format="*M"/></p>
<p>
<anchor>Send this mail
<go method="post" href="http://some.host/mailhandler"?action=send/">
<postfield name="from" value="$(from)"/>
<postfield name="to" value="$(to)"/>
<postfield name="subject" value="$(subject)"/>
<postfield name="body" value="$(body)"/>
</go>
</anchor>
</p>
</card>
</wml>
在代碼中的http://some.host/mailhandler是一個CGI程序,它是服務端的腳本程序,將提交的表單轉換成E-Mail格式併發送出去。
如果想使用一個類似於發信的過程,就需要編輯變量名。另外發送的數據是有限的,長信息可能需要打斷。
開發者需要一個WAP網關嗎?
不是很必要。如果只想進行簡單的WAP內容服務,可以使用現有的Web服務器(只需要修改MIME類型)。移動電話會通過坐落在本地的網關連接到你的服務器上。
但是在網關上駐留開發者的程序有很多好處。既然開發者的程序是網關的一個部分,開發者就可以知道呼叫號碼、身份、位置等等。
5. 可以看到WML的源代碼麼?
如果開發者使用SDK瀏覽的時候將能夠看到WML的代碼。如果只有一個HTML瀏覽器,可以訪問"Fetch Page"服務(http://www.webcab.de)來取得代碼。這個可以顯示在Internet上的任何WML頁面中。
27. 怎樣防止從Cache中讀取WML頁面?
<%
Response.ContentType = "text/vnd.wap.wml"
Response.Expires = -1
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Cache-Control", "no-cache, must-revalidate"
%>
使用META的例子經過86400秒(24 hours)後過期:
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
<meta forua="true" http-equiv="Cache-Control" content="max-age=86400"/>
</head>
<card id="expire1day">
<p>This card will live in the cache for a day</p>
</card>
</wml>
用戶手機號碼和手機型號均在HTTP的HEADER中包含,說明如下。
(1) 用戶手機號碼
(2) 手機型號
必須要電信部門批准的Sp/Cp纔可以
如何使用WAP設備發送E-Mail?
在HTML中有一個默認的E-Mail機制:" mailto:" 。但在WML中不好使,因此E-Mails必須通過WML表單來解決。例如:
<wml>
<card id="edit" title="Email Editor">
<p>From: <input type="text" name="from" format="*M"/></p>
<p>To: <input type="text" name="to" format="*M"/></p>
<p>Subject: <input type="text" name="subject" format="*M"/></p>
<p>Message body: <input type="text" name="body" format="*M"/></p>
<p>
<anchor>Send this mail
<go method="post" href="http://some.host/mailhandler"?action=send/">
<postfield name="from" value="$(from)"/>
<postfield name="to" value="$(to)"/>
<postfield name="subject" value="$(subject)"/>
<postfield name="body" value="$(body)"/>
</go>
</anchor>
</p>
</card>
</wml>
怎麼能夠知道請求是從WML瀏覽器來的還是HTML瀏覽器來的?
獲取HTTP_ACCEPT值,判斷是否爲"VND.WAP.WML"
<%
Response.Buffer = TRUE
Dim IsWap
httpAccept = LCase(Request.ServerVariables("HTTP_ACCEPT"))
if Instr(httpAccept,"wap") then
IsWap=1
Else Response.Redirect "/index.html" : Response.Flush : Response.End
End if
%>
<%Response.ContentType = "text/vnd.wap.wml"%><?xml version="1.0"?>
<%Response.Flush%>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="redirect">
<onevent type="onenterforward">
<go href="/index.wml"/>
</onevent>
<p>
<a href="/index.wml">enter</a>
</p>
</card>
</wml>
<%Response.Flush:Response.End%>
如何判斷訪問者是來自哪個瀏覽器或者移動電話?
可以通過檢查HTTP_USER_AGENT標籤來判斷。例如試着使用Microsoft Internet Explorer訪問一個站點的時候,HTTP_USER_AGENT將返回:Mozilla/4.0 (compatible;MSIE 5.0; Windows 98);在同樣的情況下使用Nokia 7110訪問這個站點,HTTP_USER_AGENT就會是:Nokia7110/1.0(04.73)。據此可以判斷用戶代理是什麼類型的。
2. 利用Wap頁面進行直接撥打電話號碼
把下邊的代碼放到:<p></p>之間。
<input name="phone_no" format="*m" value="13"/>
<do type="option" label="呼出號">
<go href="wtai://wp/mc;$(phone_no)"/>
</do><br/>
或者直接寫入電話號碼的方式:
<a href="wtai://wp/mc;1331597312*">撥打電話</a>
3. Asp中Gb2312轉UTF-8程序
把下面的代碼粘貼到ASP+WMl的文件中。
<%
Function uni(Chinese)
For i = 1 to Len (Chinese)
a=Mid(Chinese, i, 1)
uni=uni & "&#x" & Hex(Ascw(a)) & ";"
next
End Function
%>
使用方法:
<a title="<%=Uni("確定")%>" href="http://www.51omeng.com/bicyle/bikewap/index.asp"><%=Uni("歡迎光臨被愛可以")%></a><br/>
<do type="prev" name="Prev" label="後退"><prev/></do>
我的wap開發經驗總結
1. 錯誤連接
response.write "<a href='http://m2p.cn/txl.asp?mobileno="&mobilenum&”&file="&file&”'>通訊錄</a>"
& 替換 &
response.write "<a href='http://m2p.cn/txl.asp?mobileno="&mobileno&"&page="&s2-1&"&file="&file&"'>上一頁</a>"
2. 不能傳遞中文,需要編碼
''用URLEncode方法進行編碼
strurlencode=server.URLEncode(str) //能夠取出中文
例如:response.write "<a href='http://m2p.cn/kjj.asp?mobileno="&mobileno&"&host="&host&"&comm="&server.URLEncode(mid(v(2*i+1),1,j-1))&"'>"&mid(v(2*i+1),j+1,len(v(2*i+1))-j)&"</a>"
''用HTMLEncode方法進行編碼
strhtmlencode=server.HTMLEncode (str)
撥打電話
<a href='"&"wtai://wp/mc;"&mid(v(2*i+1),1,j-1)&"'>"&mid(v(2*i+1),j+1,len(v(2*i+1))-j)&"</a>"
3. Wap不保存cashe,強制刷新
<meta http-equiv="Cache-Control" content="max-age=0" />
<meta http-equiv="Cache-control" content="no-cache" />
5.按鍵上加連接
<do type="options" label="回首頁">
<go href="http://wap.un165.com/" />
</do>
4. 常見錯誤
m3gate命令提示
Fatal Error. Ln 10 .Col 10
Expected end of tag ‘p’
response.write "命令已執行</br>"
正確寫法
response.write “命令已執行”
response.write “<br/>”
5. 同一連接wap不能重複操作
文本需要翻頁,因爲每一次點擊”下一頁”傳遞的連接是相同的
手機不執行重複操做
解決:方法 添加一個動態參數 &time=now
6. 對於wap的自動換行
<p mode='nowrap'>強制不讓系統自動換行
自動刷新
<card id="c1" ontimer="#c1">
<timer value="20"/>
<p align="center">
test card1
</p>
</card>
右返回軟鍵
<do type="options" label="返回" name="home">
<spawn href="XXX.wml">
</do>
利用Wap頁面進行直接撥打電話號碼
2. 利用Wap頁面進行直接撥打電話號碼
把下邊的代碼放到:<p></p>之間。
<input name="phone_no" format="*m" value="13"/>
<do type="option" label="呼出號">
<go href="wtai://wp/mc;$(phone_no)"/>
</do><br/>
或者直接寫入電話號碼的方式:
<a href="wtai://wp/mc;1331597312*">撥打電話</a>
3. Asp中Gb2312轉UTF-8程序
把下面的代碼粘貼到ASP+WMl的文件中。
<%
Function uni(Chinese)
For i = 1 to Len (Chinese)
a=Mid(Chinese, i, 1)
uni=uni & "&#x" & Hex(Ascw(a)) & ";"
next
End Function
%>
使用方法:
<a title="<%=Uni("確定")%>" href="http://www.51omeng.com/bicyle/bikewap/index.asp"><%=Uni("歡迎光臨被愛可以")%></a><br/>
wap服務器配置
text/vnd.wap.wml wml image/vnd.wap.wbmp wbmp
text/vnd.wap.wmls wmls
application/vnd.wap.wmlc wmlc
application/vnd.wap.wmlscriptc wmlsc
text/vnd.wap.wmlscript wsc
text/vnd.wap.wmlscript wmlscript
OTA配置
application/java-archive jar
text/vnd.sun.j2me.app-descriptor jad
獲取wml源代碼
http://webcab.de/fetchpage.htm