ACTIVE SERVER PAGE > URLEncode - ANSI - ÀÎÄÚµù ÇÏÀÚ. URLEcode ÇÔ¼ö
µî·ÏÀÏ : 2017-07-04 17:48
Á¶È¸¼ö : 52,687
ASP¿¡¼ ¼ýÀÚ, ¾ËÆĺª ¹®ÀÚ°¡ ¾Æ´Ñ °Í(0~9, a~zÀÌ ¾Æ´Ñ ¹®ÀÚ)À» ¾Æ½ºÅ° Çí»ç ÄÚµå·Î º¯È¯½ÃÄÑÁÖ´Â ¸Þ½îµå°¡ ÀÖ´Ù.
±×°ÍÀº ¹Ù·Î Server.UrlEncodeÀÌ´Ù.
À̹ø½Ã°£¿¡´Â ÀÌ ÇÔ¼ö¸¦ »ç¿ëÇÏÁö ¾Ê°í ´Ù¸¥ ÇÔ¼ö¸¦ ÀÌ¿ëÇؼ URL ÀÎÄÚµù Çغ¸ÀÚ.
´ë»ó¹®ÀÚ¿
http://ankyu.entersoft.kr/default.asp?id=123&usr=ankyu&key=¿£ÅͼÒÇÁÆ®
Server.URLEncode() »ç¿ë ¿¹
http%3A%2F%2Fankyu%2Eentersoft%2Ekr%2Fdefault%2Easp%3Fid%3D123%26usr%3Dankyu%26key%3D%BF%A3%C5%CD%BC%D2%C7%C1%C6%AE
URLEncode() ÇÔ¼ö »ç¿ë ¿¹
http%3A%2F%2Fankyu.entersoft.kr%2Fdefault.asp%3Fid%3D123%26usr%3Dankyu%26key%3D%BF%A3%C5%CD%BC%D2%C7%C1%C6%AE
Public Function URLEncode(URLStr)
Dim sURL '** ÀԷ¹ÞÀº URL ¹®ÀÚ¿
Dim sBuffer '** Encoding ÁßÀÇ URL À» ´ãÀ» Buffer ¹®ÀÚ¿
Dim sTemp '** Àӽà ¹®ÀÚ¿
Dim cChar '** URL ¹®ÀÚ¿ ÁßÀÇ ÇöÀç Index ÀÇ ¹®ÀÚ
Dim Index
On Error Resume Next
Err.Clear
sURL = Trim(URLStr) '** URL ¹®ÀÚ¿À» ¾ò´Â´Ù.
sBuffer = "" '** Àӽà Buffer ¿ë ¹®ÀÚ¿ º¯¼ö ÃʱâÈ.
'******************************************************
'* URL Encoding ÀÛ¾÷
'******************************************************
For Index = 1 To Len(sURL)
'** ÇöÀç Index ÀÇ ¹®ÀÚ¸¦ ¾ò´Â´Ù.
cChar = Mid(sURL, Index, 1)
If cChar = "0" Or _
(cChar >= "1" And cChar <= "9") Or _
(cChar >= "a" And cChar <= "z") Or _
(cChar >= "A" And cChar <= "Z") Or _
cChar = "-" Or _
cChar = "_" Or _
cChar = "." Or _
cChar = "*" Then
'** URL ¿¡ Çã¿ëµÇ´Â ¹®ÀÚµé :: Buffer ¹®ÀÚ¿¿¡ Ãß°¡ÇÑ´Ù.
sBuffer = sBuffer & cChar
ElseIf cChar = " " Then
'** °ø¹é ¹®ÀÚ :: + ·Î ´ëüÇÏ¿© Buffer ¹®ÀÚ¿¿¡ Ãß°¡ÇÑ´Ù.
sBuffer = sBuffer & "+"
Else
'** URL ¿¡ Çã¿ëµÇÁö ¾Ê´Â ¹®ÀÚµé :: % ·Î Encoding Çؼ Buffer ¹®ÀÚ¿¿¡ Ãß°¡
sTemp = CStr(Hex(Asc(cChar)))
If Len(sTemp) = 4 Then
sBuffer = sBuffer & "%" & Left(sTemp, 2) & "%" & Mid(sTemp, 3, 2)
ElseIf Len(sTemp) = 2 Then
sBuffer = sBuffer & "%" & sTemp
End If
End If
Next
'** Error ó¸®
If Err.Number > 0 Then
URLEncode = ""
Exit Function
End If
'** °á°ú¸¦ ¸®ÅÏÇÑ´Ù.
URLEncode = sBuffer
Exit Function
End Function
Function URLEncode_Gb(ByVal str)
Dim i,s
Dim B,bCode,gb,Hight8b,Low8b
s = ""
For i = 1 To Len(str)
B = Mid(str,i,1)
bCode=Abs(Asc(B))
If (bCode>=48 And bCode<=57) Or (bCode>=65 And bCode<=90) Or (bCode>=97 And bCode<=122) Or bCode=42 Or bCode=45 Or bCode=46 Or bCode=64 Or bCode=95 Then
s=s & B
ElseIf bCode=32 Then
s=s & "+"
ElseIf bCode<128 Then
s=s & "%" & Right("00" & Hex(bCode),2)
Else
gb = Asc(B)
If gb < 0 Then
gb = gb + &H10000
End If
Hight8b = (gb And &HFF00) / &H100
Low8b = gb And &HFF
s = s & "%" & Hex(Hight8b) & "%" & Hex(Low8b)
End If
Next
URLEncode_Gb = s
End Function