海外邮件中继,海外退信中继,美国高速VPS,不限流量VPN,邮局维护和管理,邮件网关,EMOS邮件中继,POSTFIX邮件中继,Winwebmail邮件中继,Winmail邮件中继,DBMail邮件中继,JDMail邮件中继,Exchange邮件中继,MDaemon邮件中继 淘宝店:http://shantan.taobao.com 云邮科技官网:www.yunrelay.com
【字体设置:大 中 小】
URLEncode
URLEncode 方法可以将指定字符串进行URL编码。
语法
Server.URLEncode( string )
参数
string 指定要转化的字符串
Example
下面是代码:
< % Respones.Write(Server.URLEncode("http://www.microsoft.com"))% >
显示为:
http%3A%2F%2Fwww%2Emicrosoft%2Ecom
在asp.net 解码的方法是:server.urlencode,在ASP中没有带对应的解码函数,只有自定义:
1.
<%
response.write "原码:" & "mms%3a%2f%2fmedia.chinabroadcast.cn%2fchi%2fnet_radio%2fentertainment%2fei041118002.wmv" & "<BR>"
response.write "编码后:" & server.URLEncode("mms%3a%2f%2fmedia.chinabroadcast.cn%2fchi%2fnet_radio%2fentertainment%2fei041118002.wmv") & "<BR>"
response.write "解码后:" & urldecode(server.URLEncode("mms%3a%2f%2fmedia.chinabroadcast.cn%2fchi%2fnet_radio%2fentertainment%2fei041118002.wmv"))
Function URLDecode(enStr)
Dim deStr
Dim tempC,tempI,tempV
deStr=""
For tempI=1 to len(enStr)
tempC=Mid(enStr,tempI,1)
IF tempC="%" Then
tempV=eval("&h"+Mid(enStr,tempI+1,2))
IF tempV<128 Then
deStr=deStr&chr(tempV)
tempI=tempI+2
Else
IF isvalidhex(mid(enstr,tempI,3)) then
IF isvalidhex(mid(enstr,tempI+3,3)) then
tempV=eval("&h"+Mid(enStr,tempI+1,2)+Mid(enStr,tempI+4,2))
deStr=deStr&chr(tempV)
tempI=tempI+5
Else
tempV=eval("&h"+Mid(enStr,tempI+1,2)+cstr(hex(asc(Mid(enStr,tempI+3,1)))))
deStr=deStr&chr(tempV)
tempI=tempI+3
End IF
Else
destr=destr&tempC
End IF
End IF
Else
IF tempC="+" then
deStr=deStr&" "
Else
deStr=deStr&tempC
End IF
End IF
Next
URLDecode=deStr
End Function
Function isvalidhex(str)
Dim tempD
isvalidhex=true
str=ucase(str)
IF len(str)<>3 Then isvalidhex=false:exit function
IF left(str,1)<>"%" Then isvalidhex=false:exit function
tempD=mid(str,2,1)
IF not (((tempD>="0") and (tempD<="9")) or ((tempD>="A") and (tempD<="Z"))) Then isvalidhex=false:exit function
tempD=mid(str,3,1)
IF not (((tempD>="0") and (tempD<="9")) or ((tempD>="A") and (tempD<="Z"))) Then isvalidhex=false:exit function
End Function
%>
2.
<%
function urldecoding(vstrin)
dim i,strreturn,strSpecial
strSpecial = "!""#$%&'()*+,./:;<=>?@[]^`{|}~%"
strreturn = ""
for i = 1 to len(vstrin)
thischr = mid(vstrin,i,1)
if thischr="%" then
intasc=eval("&h"+mid(vstrin,i+1,2))
if instr(strSpecial,chr(intasc))>0 then
strreturn= strreturn & chr(intasc)
i=i+2
else
intasc=eval("&h"+mid(vstrin,i+1,2)+mid(vstrin,i+4,2))
strreturn= strreturn & chr(intasc)
i=i+5
end if
else
if thischr="+" then
strreturn= strreturn & " "
else
strreturn= strreturn & thischr
end if
end if
next
urldecoding = strreturn
end function
%>
<%=urldecoding("mms%3a%2f%2fmedia.chinabroadcast.cn%2fchi%2fnet_radio%2fentertainment%2fei041118002.wmv")%>
3.
利用XMLHTTP方法。
让Request那个东西解析它,然后把内容返回过来
2个文件
第一个:url.asp
代码如下。。
<%@Language="JavaScript"%>
<%
function getURL(f_url) {
var pat = //[^./]+.[A-Za-z]+/;
var url = "http://";
url += Request.ServerVariables("HTTP_HOST");
url += Request.ServerVariables("URL");
url = url.replace(pat, "");
url += "/" + f_url;
return url;
}
function changeCode(f_val) {
var url = getURL("ChangeCode.asp") + "?Val=" + f_val;
var obj = Server.CreateObject("Microsoft.XMLHTTP");
obj.Open("POST", url, false);
obj.Send(null);
var nStrng = unescape(obj.responseText);
obj = null;
return nStrng;
}
var str = "mms%3a%2f%2fmedia.chinabroadcast.cn%2fchi%2fnet_radio%2fentertainment%2fei041118002.wmv";
Response.Write(changeCode(str));
%>
第二个文件ChangeCode.asp
代码如下。。。
<%@Language="JavaScript"%>
<%
var strng = Request.QueryString("Val");
strng = escape(strng);
Response.Write(strng);
%>
虽然比较麻烦,但是为了效果要不则手段。
---------------------------------------------------------------------------------------------------------------------------------
function urldecode(encodestr)
newstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c="+" then
newstr=newstr & " "
elseif char_c="%" then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint("&H" & next_1_c)
if havechar then
havechar=false
newstr=newstr & chr(cint("&H" & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then
newstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newstr=newstr & char_c
end if
next
urldecode=newstr
end function
发表评论 - 不要忘了输入验证码哦!