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