Function Code for ASP to read Request. QueryString Encoding

Source: Internet
Author: User

1. Does the parameter support Chinese characters only? A = Shen Shan laxiong
2. Supported parameter gb2312 Urlencode encoding :? A = % C9 % EE % C9 % BD % C0 % CF % D0 % DC
3. Support Parameter UTF-8 Urlencode encoding :? A = % E6 % B7 % B1 % E5 % B1 % B1 % E8 % 80% E7 % 81% 8A Copy codeThe Code is as follows: <% @ LANGUAGE = "VBSCRIPT" CODEPAGE = "65001" %>
<%
Option Explicit
Const YXCMS_CHARSET = "UTF-8"
Const YXCMS_CODEPAGE = 65001
Response. CharSet = "UTF-8"
Session. CodePage = 65001
'Test URL
'? N1 = Shen Shan old bear & n2 = % C9 % EE % C9 % BD % C0 % CF % D0 % DC & n3 = % E6 % B7 % B1 % E5 % B1 % B1 % E8 % 80% 81% E7 % 86% 8A
'Shan Shan old bear
'Gbk: % C9 % EE % C9 % BD % C0 % CF % D0 % DC
'Utf-8: % E6 % B7 % B1 % E5 % B1 % B1 % E8 % 80% 81% E7 % 86% 8A
Dim URI, key
Set URI = new Cls_URI
'Test all output parameters
For Each key In URI. QueryString
Response. Write "<span style = 'color: red'>" & key & ": </span>" & URI. Get (key) & "Next
'Retrieve a single value
'Uri. Get ("name ")
'--------------------------------------------
'Asp UTF-8 encoding by GBK UTF-8 Encoding
'Author: Shen Shan old bear QQ: 81090
'--------------------------------------------
Class Cls_URI
Private o_item, o_regx
Private url_query
Private Sub Class_Initialize
Set o_item = CreateObject ("Scripting. Dictionary ")
O_item.CompareMode = 1
Set o_regx = New Regexp
O_regx.Pattern = "^ (? : [\ X00-\ x7f] | [\ xfc-\ xff] [\ x80-\ xbf] {5} | [\ xf8-\ xfb] [\ x80-\ xbf] {4} | [\ xf0-\ xf7] [\ x80-\ xbf] {3} | [\ xe0-\ xef] [\ x80-\ xbf] {2} | [\ xc0-\ xdf] [\ x80-\ xbf]) + $"
Session. CodePage = 936
Url_query = Request. ServerVariables ("QUERY_STRING ")
Session. CodePage = 65001
'Generate a simulated QueryString value based on the QUERY_STRING string
Dim I, a, B, c, n, v
A = Split (url_query, "&"): c = UBound ()
For I = 0 To c
B = Split (a (I), "=", 2)
N = Trim (B (0 )&"")
If UBound (B) <1 Then
V = ""
Else
V = B (1)
If InStr (v, "%")> 0 Then v = URLDecode (v)
End If
If n <> "" Then
O_item (n) = v
End If
Next
Set o_regx = Nothing
End Sub
Private Sub Class_Terminate
Set o_item = Nothing
End Sub
'Simulate Request. QueryString
Public Function QueryString ()
Set QueryString = o_item
End Function
'Simulate Request. QueryString (n)
Public Function [GET] (n)
If o_item.Exists (n) Then
[GET] = o_item.Item (n)
Else
[GET] = ""
End If
End Function
'Encoding and formatting
Private Function URLDecode (ByVal s)
Dim sm, cs, r, o_regex
If Trim (s & "") = "" Then
URLDecode = s: Exit Function
End If
S = unescape (s)
If o_regx.Test (s) Then
Cs = "UTF-8"
Else
Cs = "GBK"
End If
Set sm = CreateObject ("Adodb. Stream ")
With sm
. Type = 2
. Mode = 3
. Open
. CharSet = "ISO-8859-1"
. WriteText s
. Position = 0
. CharSet = cs
URLDecode =. ReadText (-1)
. Close
End
Set sm = Nothing
End Function
End Class
%>
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.