UrlEncode, UrlDecode Custom Function _ application techniques implemented in ASP

Source: Internet
Author: User
Tags chr eval urlencode

In the Ajax post, found in the server to get data is always garbled, online see some solutions are also uncertain, I post the past is an XML form, because the garbled server-side XML can not parse or error. So before the post to encode it, to the server and then decode, so the problem is solved, but if the data is very large estimates will affect the speed.

While the Request in ASP automatically decodes a URL-encoded string, Request.BinaryRead (request.totalbytes) does not decode it when it obtains post data, so it is decoded.

Here's what I found. Decoding function of Server.URLEncode function in ASP

Copy Code code as follows:

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&AMP;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

Plus an encoding function, which is different from the Server.URLEncode: Server.URLEncode will label HTML or XML, such as
will also be encoded, and the following function will not. I use the following to encode, and then decode, because I use the post with XML.

Copy Code code as follows:

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.