ASP中实现的URLEncode、URLDecode自定义函数

在做ajax中的post时,发现在服务器端取得数据时总是乱码,网上看了些解决方法也搞不定,我post过去时是xml形式,由于乱码服务器端xml也解析不了或出错。于是在post前先把它编码,到服务器端再解码,这样问题解决了,但是要是数据很大时估计会很影响速度。

虽然ASP中的request会自动解码经过url编码的字符串,但是Request.BinaryRead(Request.TotalBytes)取得post数据时却不会解码,所以要进行解码。

下面是我找到的一个ASP中server.urlencode函数的解码函数

复制代码 代码如下:
Function URLDecode(enStr)
  dim deStr,strSpecial
  dim c,i,v
    deStr=""
    strSpecial="!""#$%&'()*+,.-_/:;< =>?@[/]^`{|}~%"
    for i=1 to len(enStr)
      c=Mid(enStr,i,1)
      if c="%" then
        v=eval("&h"+Mid(enStr,i+1,2))
        if inStr(strSpecial,chr(v))>0 then
          deStr=deStr&chr(v)
          i=i+2
        else
          v=eval("&h"+ Mid(enStr,i+1,2) + Mid(enStr,i+4,2))
          deStr=deStr & chr(v)
          i=i+5
        end if
      else
        if c="+" then
          deStr=deStr&" "
        else
          deStr=deStr&c
        end if
      end if
    next
    URLDecode=deStr
End function

再附一个编码函数,这个与server.urlencode不一样之处是:server.urlencode会将html或xml等标签,如
也会进行编码,而下面这个函数不会。我是用下面的进行编码,再解码,因为我用post时用xml的。
复制代码 代码如下:
private Function URLEncoding(vstrIn)
    strReturn = ""
    For i = 1 To Len(vstrIn)
    ThisChr = Mid(vStrIn,i,1)
    If Abs(Asc(ThisChr)) < &HFF Then
    strReturn = strReturn & ThisChr
    Else
    innerCode = Asc(ThisChr)
    If innerCode < 0 Then
    innerCode = innerCode + &H10000
    End If
    Hight8 = (innerCode And &HFF00)/ &HFF
    Low8 = innerCode And &HFF
    strReturn = strReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
    End If
    Next
    URLEncoding = strReturn
  End Function

时间: 2024-07-31 04:39:42

ASP中实现的URLEncode、URLDecode自定义函数的相关文章

ASP中的ArrayList类[数组常用函数]

ASP中的ArrayList类[数组常用函数] 使用方法如下:  程序代码 <% dim arr : set arr=new ArrayList arr.add "a" : arr.add "b" : arr.add "c" Response.Write arr.count & "<br>" for i=0 to arr.count-1     Response.Write arr.item(i) &

ASP中实现的URLEncode、URLDecode自定义函数_应用技巧

在做ajax中的post时,发现在服务器端取得数据时总是乱码,网上看了些解决方法也搞不定,我post过去时是xml形式,由于乱码服务器端xml也解析不了或出错.于是在post前先把它编码,到服务器端再解码,这样问题解决了,但是要是数据很大时估计会很影响速度. 虽然ASP中的request会自动解码经过url编码的字符串,但是Request.BinaryRead(Request.TotalBytes)取得post数据时却不会解码,所以要进行解码. 下面是我找到的一个ASP中server.urlen

ASP中加密与解密对应的函数

函数|加密|解密 在ASP中加密方法有对应的解密方法好象不多,现在根据前辈资料整理出在asp中加密与解密函数 rsa.asp<%rem 在ASP中实现加密与解密,加密方法:根据RSArem 联系:hnsoso@sina.comClass clsRSA Public PrivateKeyPublic PublicKeyPublic Modulus Public Function Crypt(pLngMessage, pLngKey)On Error Resume NextDim lLngModDi

一段在asp中加密与解密对应的函数

函数|加密|解密 在ASP中加密方法有对应的解密方法好象不多,现在根据前辈资料整理出在asp中加密与解密函数 rsa.asp <% rem 在ASP中实现加密与解密,加密方法:根据RSA rem 联系:hnsoso@sina.com Class clsRSA Public PrivateKey Public PublicKey Public Modulus Public Function Crypt(pLngMessage, pLngKey) On Error Resume Next Dim l

在asp中加密与解密对应的函数

函数|加密|解密 在ASP中加密方法有对应的解密方法好象不多,现在根据前辈资料整理出在asp中加密与解密函数 rsa.asp<%rem 在ASP中实现加密与解密,加密方法:根据RSArem 联系:hnsoso@sina.comClass clsRSA Public PrivateKey Public PublicKey Public Modulus Public Function Crypt(pLngMessage, pLngKey) On Error Resume Next Dim lLngM

一段在asp中加密与解密对应的函数_应用技巧

在ASP中加密方法有对应的解密方法好象不多,现在根据前辈资料整理出在asp中加密与解密函数 rsa.asp <% rem 在ASP中实现加密与解密,加密方法:根据RSA rem 联系:hnsoso@sina.com Class clsRSA Public PrivateKey Public PublicKey Public Modulus   Public Function Crypt(pLngMessage, pLngKey) On Error Resume Next Dim lLngMod

Sql Server中常用的6个自定义函数分享_MsSql

在日常应用中,往往根据实际需求录入一些值,而这些值不能直接使用,所以Sql中经常会对字段值进行一些常规的处理.这里搜集了(提取数字.英文.中文.过滤重复字符.分割字符的方法),方便日后查询使用.   一.判断字段值是否有中文 --SQL 判断字段值是否有中文 create function fun_getCN(@str nvarchar(4000)) returns nvarchar(4000) as begin declare @word nchar(1),@CN nvarchar(4000)

ASP 中对 IP 进行过滤限制函数

函数 <%'获取访问者的地址ip=Request.ServerVariables("REMOTE_ADDR") '允许的IP地址段为10.0.0.0-10.68.63.255allowip1="10.0.0.0"allowip2="10.68.10.71" response.write checkip(ip,allowip1,allowip2) function checkip(ip,allowip1,allowip2)dim check(

asp中对ip进行过滤限制函数

函数 看了一些IP限制的函数,觉得太复杂.所以,试着写了一个,比较简单.请网友参考指教.谢谢!- 代码拷贝框<%'获取访问者的地址ip=Request.ServerVariables("REMOTE_ADDR") '允许的IP地址段为10.0.0.0-10.68.63.255allowip1="10.0.0.0"allowip2="10.68.10.71"response.write checkip(ip,allowip1,allowip2