Home>

Encountered a decoding problem when developing with asp.Although the encoded URL string is automatically decoded using request in asp,But request.binaryread (request.totalbytes) does not decode the post data.So it can only be decoded manually.

asp decoding function:

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

Just a personal hobby,I researched the implementation ideas of coding myself,Finally I wrote an encoding function myself,For your reference.Note:asp has a built-in encoding function,This is server.urlencode.

asp encoding function:

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

Suggest that when coding in Chinese,Still use asp built-in functions.Although the above coding function has been tested n times, no problem has been found.But just in case there is a bug.

asp
  • Previous How to solve the problem when using WordPress's $wpdb class to read the mysql database and do ajax
  • Next Share five useful jquery tips