Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: LeandroA en 18 Diciembre 2012, 04:47 am



Título: [Reto] UrlEncode y UrlDecode
Publicado por: LeandroA en 18 Diciembre 2012, 04:47 am
Hola, se me presento la necesidad de crear esas funciones y en la web encontré algunas pero no funcionan muy bien asi que me pareció interesante el reto, no es muy dificil (creo), pero es para ver quien las puede hacer funcionar mas rapido.

Código:
Public Function URLDecode(ByVal sURL As String, Optional ByVal SpacePlus As Boolean = True) As String
Public Function URLEncode(ByVal sURL As String, Optional ByVal SpacePlus As Boolean = True) As String
el segundo parametro es opcional para remplazar espacios por +

es practicamente como lo que hace esta web http://meyerweb.com/eric/tools/dencoder/



osea ingresamos

Citar
https://www.google.com.ar/search?q=canción
si usamos la funcion urlEncode deberia cambiar el acento
Citar
https://www.google.com.ar/search?q=canci%C3%B3n
por lo visto esta pasado a utf8 y luego a hex
lo importante es que encode los parámetros no la url entera ya que sino dejaria de ser una url valida.

otro ejemplos
Citar
http://www.taringa.net/buscar/?q=día 12/12/12&interval=
http://www.taringa.net/buscar/?q=d%C3%ADa%2012%2F12%2F12&interval=

Citar
https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http://mail.live.com/default.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1

https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1

después iremos debatiendo que esta mal o que falta.


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: MCKSys Argentina en 18 Diciembre 2012, 14:09 pm
Encontré errores en el código, así que lo quito.

Cuando lo tenga, lo pongo...  :P


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: Danyfirex en 18 Diciembre 2012, 17:18 pm
Aquí esta el Encode  ;D creo que es lo que se quiere, al rato traigo el Decode


Código
  1. Function URLEncode(url As String) As String
  2. Dim sp() As Byte
  3. Dim final As String
  4.  
  5. sp() = StrConv(url, vbFromUnicode)
  6.  
  7. For i = 0 To UBound(sp)
  8.  
  9. Select Case sp(i)
  10.  
  11.    Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
  12.         final = final & Chr(sp(i))
  13.  
  14.    Case 32
  15.        final = final & "+"
  16.  
  17.   Case Else
  18.           final = final & "%" & Hex(sp(i))
  19. End Select
  20.  
  21. Next
  22. URLEncode= final
  23. End Function


Edito:

aqui esta el Decode.

Código
  1. Function URLDecode(url As String) As String
  2. Dim spl() As String
  3. Dim final As String
  4. Dim str As String
  5. str = Replace(url, "+", " ")
  6. spl() = Split(str, "%")
  7. final = spl(0)
  8. For i = 1 To UBound(spl)
  9. final = final & Chr(CLng("&H" & Left(spl(i), 2))) & Mid(spl(i), 3)
  10. Next
  11. URLDecode = final
  12. End Function

saludos

PD: lo hice a base de uno que vi en Autoit


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: cobein en 19 Diciembre 2012, 02:45 am
Leandro no podes usar InternetCanonicalizeUrl ?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa384342(v=vs.85).aspx


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: LeandroA en 19 Diciembre 2012, 04:28 am
bien, ya estoy algo confuso, cobein probé con InternetCanonicalizeUrl no se si pueda decir si funciona o no es algo que no me queda claro, el api trabaja igual que  UrlEscape (http://msdn.microsoft.com/en-us/library/windows/desktop/bb773774(v=vs.85).aspx) pero no codifica los caracteres al igual que cuando los copio de la barra del navegador, de todas formas la url parce andar bien.

Código
  1. Option Explicit
  2. Private Declare Sub InternetCanonicalizeUrl Lib "wininet.dll" Alias "InternetCanonicalizeUrlA" (ByVal lpszUrl As String, ByVal lpszBuffer As String, ByRef lpdwBufferLength As Long, ByVal dwFlags As Long)
  3. Private Const INTERNET_MAX_URL_LENGTH As Long = 2048
  4. Private Const ICU_BROWSER_MODE As Long = &H2000000
  5. Private Const ICU_DECODE As Long = &H10000000
  6. Private Const ICU_ENCODE_PERCENT As Long = &H1000
  7. Private Const ICU_ENCODE_SPACES_ONLY As Long = &H4000000
  8. Private Const ICU_NO_ENCODE As Long = &H20000000
  9. Private Const ICU_ESCAPE As Long = &H80000000
  10. Private Const ICU_NO_META As Long = &H8000000
  11.  
  12.  
  13. Private Sub Form_Load()
  14.    Debug.Print UrlEncode("https://www.google.com.ar/search?q=canción animal")
  15.    'https://www.google.com.ar/search?q=casa%20duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr%3A1%2Ccd_min%3A5%2F12%2F2012%2Ccd_max%3A18%2F12%2F2012&tbm=isch
  16.    Debug.Print UrlEncode("https://www.google.com.ar/search?q=casa duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr:1,cd_min:5/12/2012,cd_max:18/12/2012&tbm=isch")
  17. End Sub
  18.  
  19. Private Function UrlEncode(sURL As String, Optional ByVal SpacePlus As Boolean) As String
  20.  
  21.    Dim sBuffer As String, lBufferLength As Long
  22.  
  23.    sBuffer = String$(INTERNET_MAX_URL_LENGTH, 0)
  24.    lBufferLength = INTERNET_MAX_URL_LENGTH
  25.    InternetCanonicalizeUrl sURL, sBuffer, lBufferLength, ICU_ENCODE_PERCENT Or (ICU_ENCODE_SPACES_ONLY * SpacePlus)
  26.    If lBufferLength > 0 Then UrlEncode = Left$(sBuffer, lBufferLength)
  27.  
  28. End Function
  29.  

@Danyfirex la función no va por mal camino pero al remplazar los "&" la url queda inservible.



Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: MCKSys Argentina en 19 Diciembre 2012, 04:30 am
Dejo mi Encode. El decode lo hago cuando se pase la F1ACA...  ;D

Código
  1. Option Explicit
  2. Option Base 0
  3.  
  4. Enum eMaxWinInetValues
  5.  INTERNET_MAX_HOST_NAME_LENGTH = 256
  6.  INTERNET_MAX_USER_NAME_LENGTH = 128
  7.  INTERNET_MAX_PASSWORD_LENGTH = 128
  8.  INTERNET_MAX_PORT_NUMBER_LENGTH = 5          ' INTERNET_PORT is unsigned short
  9.  INTERNET_MAX_PORT_NUMBER_VALUE = 65535       ' maximum unsigned short value
  10.  INTERNET_MAX_PATH_LENGTH = 2048
  11.  INTERNET_MAX_SCHEME_LENGTH = 32              ' longest protocol name length
  12.  INTERNET_MAX_URL_LENGTH = INTERNET_MAX_SCHEME_LENGTH + 3 + INTERNET_MAX_PATH_LENGTH
  13. End Enum
  14.  
  15. Public Type URL_COMPONENTSA
  16.  dwStructSize As Long
  17.  lpszScheme As String
  18.  dwSchemeLength As Long
  19.  nScheme As INTERNET_SCHEME
  20.  lpszHostName As String
  21.  dwHostNameLength As Long
  22.  nPort As Integer
  23.  
  24.  lpszUsername As String
  25.  dwUserNameLength As Long
  26.  lpszPassword As String
  27.  dwPasswordLength As Long
  28.  
  29.  lpszUrlPath As String
  30.  dwUrlPathLength As Long
  31.  lpszExtraInfo As String
  32.  dwExtraInfoLength As Long
  33. End Type
  34.  
  35. Enum eCanonizeURL
  36.  ICU_ESCAPE = &H80000000       ' (un)escape URL characters
  37.  ICU_DECODE = &H10000000       ' Convert %XX escape sequences To characters
  38. End Enum
  39.  
  40. Enum INTERNET_SCHEME
  41.    INTERNET_SCHEME_PARTIAL = -2
  42.    INTERNET_SCHEME_UNKNOWN = -1
  43.    INTERNET_SCHEME_DEFAULT = 0
  44.    INTERNET_SCHEME_FTP
  45.    INTERNET_SCHEME_GOPHER
  46.    INTERNET_SCHEME_HTTP
  47.    INTERNET_SCHEME_HTTPS
  48.    INTERNET_SCHEME_FILE
  49.    INTERNET_SCHEME_NEWS
  50.    INTERNET_SCHEME_MAILTO
  51.    INTERNET_SCHEME_SOCKS
  52.    INTERNET_SCHEME_FIRST = INTERNET_SCHEME_FTP
  53.    INTERNET_SCHEME_LAST = INTERNET_SCHEME_SOCKS
  54. End Enum
  55.  
  56. Declare Function InternetCrackUrl Lib "WININET" Alias "InternetCrackUrlA" ( _
  57.    ByVal lpszUrl As String, _
  58.    ByVal dwUrlLength As Long, _
  59.    ByVal dwFlags As eCanonizeURL, _
  60.    lpUrlComponents As URL_COMPONENTSA) As Long
  61.  
  62. Declare Function PathIsURL Lib "shlwapi" Alias "PathIsURLA" ( _
  63.    ByVal pszPath As String) As Long
  64.  
  65. Public Const URIReserved = "!#%&'()*+,/:;=?@[]" 'Caracteres reservados
  66.  
  67. Public Function CrackURL(ByVal URL As String) As URL_COMPONENTSA
  68.  Dim c As URL_COMPONENTSA, Result As Long
  69.  
  70.  c.dwStructSize = 60
  71.  c.lpszScheme = Space(INTERNET_MAX_SCHEME_LENGTH)
  72.  c.dwSchemeLength = INTERNET_MAX_SCHEME_LENGTH
  73.  c.lpszHostName = Space(INTERNET_MAX_HOST_NAME_LENGTH)
  74.  c.dwHostNameLength = INTERNET_MAX_HOST_NAME_LENGTH
  75.  
  76.  c.lpszUsername = Space(INTERNET_MAX_USER_NAME_LENGTH)
  77.  c.dwUserNameLength = INTERNET_MAX_USER_NAME_LENGTH
  78.  c.lpszPassword = Space(INTERNET_MAX_USER_NAME_LENGTH)
  79.  c.dwPasswordLength = INTERNET_MAX_USER_NAME_LENGTH
  80.  
  81.  c.lpszUrlPath = Space(INTERNET_MAX_PATH_LENGTH)
  82.  c.dwUrlPathLength = INTERNET_MAX_PATH_LENGTH
  83.  'fix: extend size of extraInfo to len of url
  84.  c.lpszExtraInfo = Space(Len(URL))
  85.  c.dwExtraInfoLength = Len(URL)
  86.  Result = InternetCrackUrl(URL, 0, 0, c)
  87.  If Result Then
  88.    c.lpszScheme = Left$(c.lpszScheme, c.dwSchemeLength)
  89.    c.lpszHostName = Left$(c.lpszHostName, c.dwHostNameLength)
  90.  
  91.    c.lpszUsername = Left$(c.lpszUsername, c.dwUserNameLength)
  92.    c.lpszPassword = Left$(c.lpszPassword, c.dwPasswordLength)
  93.  
  94.    c.lpszUrlPath = Left$(c.lpszUrlPath, c.dwUrlPathLength)
  95.    c.lpszExtraInfo = Left$(c.lpszExtraInfo, c.dwExtraInfoLength)
  96.  Else
  97.    c.lpszScheme = ""
  98.    c.lpszHostName = ""
  99.  
  100.    c.lpszUsername = ""
  101.    c.lpszPassword = ""
  102.  
  103.    c.lpszUrlPath = ""
  104.    c.lpszExtraInfo = ""
  105.  End If
  106.  CrackURL = c
  107. End Function
  108.  
  109. Function isPrint(Car As String) As Boolean
  110. 'Devuelve si un caracter es imprimible (según: http://en.wikipedia.org/wiki/Isprint)
  111. 'Similar a isprint de C
  112. If Len(Car) <> 1 Then
  113.    isPrint = False
  114. Else
  115.    isPrint = (Asc(Car) >= 32) And (Asc(Car) <= 126)
  116. End If
  117. End Function
  118.  
  119. Function HexB(Num As Byte) As String
  120. 'Devuel el valor Hexa de un byte con padding
  121. Dim strAux As String
  122.  
  123. strAux = Hex(Num)
  124. If Len(strAux) = 1 Then
  125.    strAux = "0" + strAux
  126. End If
  127. HexB = strAux
  128. End Function
  129.  
  130. Public Function EncodeAscii(Cadena As String, SpacePlus As Boolean) As String
  131. Dim I As Long
  132. Dim Car As String
  133. Dim sRet As String
  134.  
  135. sRet = ""
  136. For I = 1 To Len(Cadena)
  137.    Car = Mid(Cadena, I, 1)
  138.    If (InStr(1, URIReserved, Car) > 0) Or (Not isPrint(Car)) Then
  139.        'contempla los espacios
  140.        If SpacePlus And (Asc(Car) = 32) Then
  141.            sRet = sRet + "+"
  142.        Else
  143.            sRet = sRet + "%"
  144.            sRet = sRet + HexB(Asc(Car))
  145.        End If
  146.    Else
  147.        'char comun
  148.        sRet = sRet + Car
  149.    End If
  150. Next I
  151. EncodeAscii = sRet
  152. End Function
  153.  
  154. Public Function isValidExtraInfo(Cadena As String) As Boolean
  155. isValidExtraInfo = (InStr(1, Cadena, "?") <> 0) And (InStr(1, Cadena, "=") <> 0)
  156. End Function
  157.  
  158. Public Function URLEncode(ByVal sURL As String, Optional ByVal SpacePlus As Boolean = True) As String
  159. Dim URLComponents As URL_COMPONENTSA
  160. Dim sParams As String
  161. Dim mExtraValues() As String
  162. Dim mExtraValuePair() As String
  163. Dim sRet As String
  164. Dim I As Long
  165. Dim Car As String
  166.  
  167. 'verifica que sea un URL válido
  168. If Not PathIsURL(sURL) Then URLEncode = ""
  169.  
  170. 'parsea URL
  171. URLComponents = CrackURL(sURL)
  172. 'URI = <scheme>://<host>/<path>;<params>?<query>#<fragment>
  173. 'M$ URL = <scheme>://<user>:<pass>@<host>/<path>;<params>?<query>#<fragment>
  174.  
  175. 'Re-Armar URL
  176. 'scheme
  177. If URLComponents.lpszScheme <> "" Then
  178.    sRet = URLComponents.lpszScheme + "://"
  179. End If
  180. 'user,pass,host,port
  181. If URLComponents.lpszUsername <> "" Then
  182.    sRet = sRet + URLComponents.lpszUsername + ":"
  183. End If
  184. If URLComponents.lpszPassword <> "" Then
  185.    sRet = sRet + URLComponents.lpszPassword + "@"
  186. End If
  187. sRet = sRet + URLComponents.lpszHostName
  188. If URLComponents.nPort <> 0 Then
  189.    sRet = sRet + ":" & URLComponents.nPort
  190. End If
  191. 'path
  192. sRet = sRet + URLComponents.lpszUrlPath
  193.  
  194. 'Ahora lo pedido: convertir los extras
  195. 'extras format: "?" + <ID> + "=" + <Value> + "&"
  196. 'lo que se encodea es sólo <Value>
  197. If (URLComponents.dwExtraInfoLength > 4) And isValidExtraInfo(URLComponents.lpszExtraInfo) Then
  198.    'para evitar errores, el largo MINIMO deberia ser de 4 caracteres: "?" + <ID> + "=" + <Value>
  199.    sRet = sRet + "?"
  200.    sParams = Mid(URLComponents.lpszExtraInfo, 2, Len(URLComponents.lpszExtraInfo))
  201.    mExtraValues = Split(sParams, "&")
  202.    For I = 0 To UBound(mExtraValues)
  203.        mExtraValuePair = Split(mExtraValues(I), "=")
  204.        sRet = sRet + mExtraValuePair(0) + "=" + EncodeAscii(mExtraValuePair(1), SpacePlus) + "&"
  205.    Next I
  206.    'borrar '&' final
  207.    sRet = Mid(sRet, 1, Len(sRet) - 1)
  208. ElseIf URLComponents.dwExtraInfoLength > 0 Then
  209.    sRet = sRet + URLComponents.lpszExtraInfo
  210. End If
  211. URLEncode = sRet
  212. End Function
  213.  
  214. Public Function URLDecode(ByVal sURL As String, Optional ByVal SpacePlus As Boolean = True) As String
  215. ''Lo inverso al Encode :)
  216. End Function
  217.  

EDIT: El código para parsear el URL lo saqué de acá: http://www.motobit.com/tips/detpg_CrackURL/ (http://www.motobit.com/tips/detpg_CrackURL/)

EDIT 2: Una cosa que noto ahora es que si la parte de los querys tiene "&" ó "=" demás, el parseo va a fallar...  :-\


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: LeandroA en 19 Diciembre 2012, 07:27 am
Tiro una utilizando las funciones de javascript, haciendo unos malabares para preservar una url valida

Código
  1. Public Function URLEncode(ByVal sUrl As String) As String
  2.    Dim objSC As Object
  3.    Dim sPart() As String
  4.    sPart = Split(sUrl, "?")
  5.    If UBound(sPart) > 0 Then
  6.        Set objSC = CreateObject("ScriptControl")
  7.        objSC.Language = "Jscript"
  8.        sPart(1) = objSC.CodeObject.encodeURIComponent(sPart(1))
  9.        sPart(1) = Replace(sPart(1), "%3D", "=")
  10.        sPart(1) = Replace(sPart(1), "%26", "&")
  11.        Set objSC = Nothing
  12.    End If
  13.    URLEncode = Join(sPart, "?")
  14. End Function
  15.  
  16. Public Function URLDecode(ByVal sUrl As String) As String
  17.    Dim objSC As Object
  18.    Set objSC = CreateObject("ScriptControl")
  19.    objSC.Language = "Jscript"
  20.    URLDecode = objSC.CodeObject.decodeURIComponent(sUrl)
  21.    Set objSC = Nothing
  22. End Function
  23.  

PD utiliza coficiación utf8
alguien sabe si CreateObject("ScriptControl") es valido para una pc que no tenga instaldo el vb?, o es una libreria que trae  windows


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: cobein en 19 Diciembre 2012, 14:27 pm
Leandro aca arme un funcion que replica lo que hace la web que posteaste. Las funciones para UTF8 las saque de tu code.

Hay que limpiar ese code porque quedo medio desastre pero bueno es simplemente a modo de ejemplo.

Nota: los caracteres reservados los saque de http://en.wikipedia.org/wiki/Percent-encoding

Código:
Option Explicit

Private Declare Function WideCharToMultiByte Lib "KERNEL32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function MultiByteToWideChar Lib "KERNEL32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
Private Const CP_UTF8                           As Long = 65001

Private Sub Form_Load()
    Debug.Print (EncodeURL("http://www.taringa.net/buscar/?q=día 12/12/12&interval="))
End Sub

Private Function EncodeURL(ByVal sURL As String) As String
    Dim bvData()    As Byte
    Dim i           As Long
    Dim sChar       As String * 1
    
    bvData = Unicode2UTF8(sURL)
    
    For i = 0 To UBound(bvData) Step 2
        sChar = Chr$(bvData(i))
        Select Case sChar
            Case "a" To "z", "A" To "Z", "0" To "9", "-", "_", ".", "~"
                EncodeURL = EncodeURL & sChar
            Case Else
                EncodeURL = EncodeURL & "%" & Right$("0" & Hex(Asc(sChar)), 2)
        End Select
    Next
End Function

Private Function DecodeURL(ByVal sURL As String) As String
    Dim bvData()    As Byte
    Dim i           As Long
    Dim sChar       As String * 1
    bvData = sURL
        
    For i = 0 To UBound(bvData) Step 2
        sChar = Chr$(bvData(i))
        If sChar = "%" Then
            DecodeURL = DecodeURL & Chr$(Val("&h" & Chr$(bvData(i + 2)) & Chr$(bvData(i + 4))))
            i = i + 4
        Else
        DecodeURL = DecodeURL & sChar
        End If
    Next
    DecodeURL = UTF82Unicode(DecodeURL)
End Function

Private Function UTF82Unicode(ByVal sUTF8 As String) As String

    Dim UTF8Size As Long
    Dim BufferSize As Long
    Dim BufferUNI As String
    Dim LenUNI As Long
    Dim bUTF8() As Byte
    
    If LenB(sUTF8) = 0 Then Exit Function
    
    bUTF8 = StrConv(sUTF8, vbFromUnicode)
    UTF8Size = UBound(bUTF8) + 1
    
    BufferSize = UTF8Size * 2
    BufferUNI = String$(BufferSize, vbNullChar)
    
    LenUNI = MultiByteToWideChar(CP_UTF8, 0, bUTF8(0), UTF8Size, StrPtr(BufferUNI), BufferSize)
    
    If LenUNI Then
        UTF82Unicode = Left$(BufferUNI, LenUNI)
    End If

End Function


Private Function Unicode2UTF8(ByVal strUnicode As String) As String

    Dim LenUNI As Long
    Dim BufferSize As Long
    Dim LenUTF8 As Long
    Dim bUTF8() As Byte
    
    LenUNI = Len(strUnicode)
    
    If LenUNI = 0 Then Exit Function
    
    BufferSize = LenUNI * 3 + 1
    ReDim bUTF8(BufferSize - 1)
    
    LenUTF8 = WideCharToMultiByte(CP_UTF8, 0, StrPtr(strUnicode), LenUNI, bUTF8(0), BufferSize, vbNullString, 0)
    
    If LenUTF8 Then
        ReDim Preserve bUTF8(LenUTF8 - 1)
        Unicode2UTF8 = StrConv(bUTF8, vbUnicode)
    End If

End Function


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: Danyfirex en 19 Diciembre 2012, 15:54 pm

@Danyfirex la función no va por mal camino pero al remplazar los "&" la url queda inservible.



No entiendo eso Que me dices? :S

igual aquí dejo un poco optimizada la función agregando Las funciones para UTF8.

Y ahora si simula bien como la pagina. http://meyerweb.com/eric/tools/dencoder/

Código
  1. Private Declare Function WideCharToMultiByte Lib "KERNEL32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
  2. Private Declare Function MultiByteToWideChar Lib "KERNEL32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
  3. Private Const CP_UTF8                           As Long = 65001
  4.  
  5.  
  6. Private Sub Form_Load()
  7. Debug.Print (URLEncode("https://www.google.com.ar/search?q=canción"))
  8. Debug.Print URLDecode(URLEncode("https://www.google.com.ar/search?q=canción"))
  9. End Sub
  10.  
  11.  
  12. Function URLEncode(url As String) As String
  13. Dim sp() As Byte
  14. Dim final As String
  15.  
  16. sp() = StrConv(Unicode2UTF8(url), vbFromUnicode)
  17.  
  18. For i = 0 To UBound(sp)
  19.  
  20. Select Case sp(i)
  21.  
  22.    Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
  23.         final = final & Chr(sp(i))
  24.  
  25.    Case 32
  26.        final = final & "+"
  27.  
  28.   Case Else
  29.           final = final & "%" & Hex(sp(i))
  30. End Select
  31.  
  32. Next
  33. URLEncode = final
  34. End Function
  35.  
  36. Function URLDecode(url As String) As String
  37. Dim spl() As String
  38. Dim final As String
  39. Dim str As String
  40. str = Replace(url, "+", " ")
  41. spl() = Split(str, "%")
  42. final = spl(0)
  43. For i = 1 To UBound(spl)
  44. final = final & Chr(CLng("&H" & Left(spl(i), 2))) & Mid(spl(i), 3)
  45. Next
  46. URLDecode = UTF82Unicode(final)
  47. End Function
  48.  
  49.  
  50.  
  51. Private Function UTF82Unicode(ByVal sUTF8 As String) As String
  52.  
  53.    Dim UTF8Size As Long
  54.    Dim BufferSize As Long
  55.    Dim BufferUNI As String
  56.    Dim LenUNI As Long
  57.    Dim bUTF8() As Byte
  58.  
  59.    If LenB(sUTF8) = 0 Then Exit Function
  60.  
  61.    bUTF8 = StrConv(sUTF8, vbFromUnicode)
  62.    UTF8Size = UBound(bUTF8) + 1
  63.  
  64.    BufferSize = UTF8Size * 2
  65.    BufferUNI = String$(BufferSize, vbNullChar)
  66.  
  67.    LenUNI = MultiByteToWideChar(CP_UTF8, 0, bUTF8(0), UTF8Size, StrPtr(BufferUNI), BufferSize)
  68.  
  69.    If LenUNI Then
  70.        UTF82Unicode = Left$(BufferUNI, LenUNI)
  71.    End If
  72.  
  73. End Function
  74.  
  75.  
  76. Private Function Unicode2UTF8(ByVal strUnicode As String) As String
  77.  
  78.    Dim LenUNI As Long
  79.    Dim BufferSize As Long
  80.    Dim LenUTF8 As Long
  81.    Dim bUTF8() As Byte
  82.  
  83.    LenUNI = Len(strUnicode)
  84.  
  85.    If LenUNI = 0 Then Exit Function
  86.  
  87.    BufferSize = LenUNI * 3 + 1
  88.    ReDim bUTF8(BufferSize - 1)
  89.  
  90.    LenUTF8 = WideCharToMultiByte(CP_UTF8, 0, StrPtr(strUnicode), LenUNI, bUTF8(0), BufferSize, vbNullString, 0)
  91.  
  92.    If LenUTF8 Then
  93.        ReDim Preserve bUTF8(LenUTF8 - 1)
  94.        Unicode2UTF8 = StrConv(bUTF8, vbUnicode)
  95.    End If
  96.  
  97. End Function
  98.  

saludos


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: 79137913 en 20 Diciembre 2012, 12:52 pm
HOLA!!!

Como va el reto, asi lo publico en la recopilación.

GRACIAS POR LEER!!!


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: cobein en 21 Diciembre 2012, 13:42 pm
Bueno ahi esta con APIs, lo unico que vi que no es igual a lo que pedis es que las barras en los parametros no las codifica... no se, en teoria codifica lo necesario segun M$.

Código
  1. '---------------------------------------------------------------------------------------
  2. ' Module      : mUrlEncode
  3. ' DateTime    : 21/12/2012 - Fin del Mundo!
  4. ' Author      : Cobein
  5. ' Mail        : cobein27@hotmail.com
  6. ' Purpose     : Encode and Decode url parameters
  7. ' Requirements: None
  8. ' Distribution: You can freely use this code in your own
  9. '               applications, but you may not reproduce
  10. '               or publish this code on any web site,
  11. '               online service, or distribute as source
  12. '               on any media without express permission.
  13. '---------------------------------------------------------------------------------------
  14. Option Explicit
  15.  
  16. Private Const ICU_ESCAPE                    As Long = &H80000000
  17. Private Const ICU_DECODE                    As Long = &H10000000
  18. Private Const CP_UTF8                       As Long = 65001
  19. Private Const ICU_BROWSER_MODE              As Long = &H2000000
  20.  
  21. Private Type URL_COMPONENTS
  22.    StructSize          As Long
  23.    Scheme              As String
  24.    SchemeLength        As Long
  25.    nScheme             As Long
  26.    HostName            As String
  27.    HostNameLength      As Long
  28.    nPort               As Long
  29.    UserName            As String
  30.    UserNameLength      As Long
  31.    Password            As String
  32.    PasswordLength      As Long
  33.    URLPath             As String
  34.    UrlPathLength       As Long
  35.    ExtraInfo           As String
  36.    ExtraInfoLength     As Long
  37. End Type
  38.  
  39. Private Declare Function InternetCrackUrl Lib "wininet.dll" Alias "InternetCrackUrlA" (ByVal lpszUrl As String, ByVal dwUrlLength As Long, ByVal dwFlags As Long, lpUrlComponents As URL_COMPONENTS) As Long
  40. Private Declare Function InternetCanonicalizeUrl Lib "wininet.dll" Alias "InternetCanonicalizeUrlA" (ByVal lpszUrl As String, ByVal lpszBuffer As String, lpdwBufferLength As Long, ByVal dwFlags As Long) As Long
  41. Private Declare Function InternetCreateUrl Lib "wininet.dll" Alias "InternetCreateUrlA" (lpUrlComponents As URL_COMPONENTS, ByVal dwFlags As Long, ByVal lpszUrl As String, lpdwUrlLength As Long) As Long
  42. Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
  43. Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
  44. Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
  45.  
  46. Public Function URLDecode(ByVal sURL As String, _
  47.       Optional ByVal bEncodeSpace As Boolean = False, _
  48.       Optional ByVal bUTF8 As Boolean = True) As String
  49.  
  50.    Dim tURL_COMPONENTS As URL_COMPONENTS
  51.  
  52.    Call CrackUrl(sURL, tURL_COMPONENTS)
  53.  
  54.    If bEncodeSpace Then
  55.        tURL_COMPONENTS.ExtraInfo = Replace(tURL_COMPONENTS.ExtraInfo, "+", " ")
  56.    End If
  57.  
  58.    URLDecode = CreateUrl(tURL_COMPONENTS, False)
  59.  
  60.    If bUTF8 Then
  61.        URLDecode = UTF82Unicode(URLDecode)
  62.    End If
  63. End Function
  64.  
  65. Public Function URLEncode(ByVal sURL As String, _
  66.       Optional ByVal bEncodeSpace As Boolean = False, _
  67.       Optional ByVal bUTF8 As Boolean = True) As String
  68.  
  69.    Dim tURL_COMPONENTS As URL_COMPONENTS
  70.  
  71.    If bUTF8 Then
  72.        sURL = Unicode2UTF8(sURL)
  73.    End If
  74.  
  75.    Call CrackUrl(sURL, tURL_COMPONENTS)
  76.  
  77.    URLEncode = CreateUrl(tURL_COMPONENTS, True)
  78.  
  79.    If bEncodeSpace Then
  80.        URLEncode = Replace(URLEncode, "%20", "+")
  81.    End If
  82. End Function
  83.  
  84. Private Function CreateUrl(ByRef tURL_COMPONENTS As URL_COMPONENTS, ByVal bEscape As Boolean) As String
  85.    Dim sBuffer As String
  86.  
  87.    sBuffer = String$(2048, 0)
  88.  
  89.    tURL_COMPONENTS.StructSize = Len(tURL_COMPONENTS)
  90.  
  91.    If InternetCreateUrl(tURL_COMPONENTS, IIf(bEscape, ICU_ESCAPE, 0), sBuffer, 2048) Then
  92.        CreateUrl = Left$(sBuffer, lstrlen(sBuffer))
  93.    End If
  94. End Function
  95.  
  96. Private Sub CrackUrl(ByVal sURL As String, ByRef tURL_COMPONENTS As URL_COMPONENTS)
  97.    Dim sBuffer As String
  98.    Dim lSize   As Long
  99.  
  100.    lSize = 2048
  101.    sBuffer = Space$(lSize)
  102.  
  103.    If InternetCanonicalizeUrl(sURL, sBuffer, lSize, ICU_BROWSER_MODE) Then
  104.  
  105.        sURL = Left$(sBuffer, lstrlen(sBuffer))
  106.  
  107.        With tURL_COMPONENTS
  108.            .StructSize = Len(tURL_COMPONENTS)
  109.            .Scheme = Space$(lSize)
  110.            .SchemeLength = lSize
  111.            .HostName = Space$(lSize)
  112.            .HostNameLength = lSize
  113.            .UserName = Space$(lSize)
  114.            .UserNameLength = lSize
  115.            .Password = Space$(lSize)
  116.            .PasswordLength = lSize
  117.            .URLPath = Space$(lSize)
  118.            .UrlPathLength = lSize
  119.            .ExtraInfo = Space$(lSize)
  120.            .ExtraInfoLength = lSize
  121.        End With
  122.  
  123.        Call InternetCrackUrl(sURL, Len(sURL), ICU_DECODE, tURL_COMPONENTS)
  124.    End If
  125. End Sub
  126.  
  127. Private Function UTF82Unicode(ByVal sData As String) As String
  128.    Dim lRet    As Long
  129.    Dim sBuffer As String
  130.  
  131.    sBuffer = Space(Len(sData))
  132.  
  133.    lRet = MultiByteToWideChar(CP_UTF8, 0, _
  134.       StrPtr(StrConv(sData, vbFromUnicode)), Len(sData), _
  135.       StrPtr(sBuffer), Len(sData))
  136.  
  137.    If lRet Then
  138.        UTF82Unicode = Left$(sBuffer, lRet)
  139.    End If
  140. End Function
  141.  
  142. Private Function Unicode2UTF8(ByVal sData As String) As String
  143.    Dim lRet    As Long
  144.    Dim sBuffer As String
  145.  
  146.    sBuffer = Space(LenB(sData))
  147.  
  148.    lRet = WideCharToMultiByte(CP_UTF8, 0, _
  149.       StrPtr(sData), Len(sData), _
  150.       StrPtr(sBuffer), Len(sBuffer), _
  151.       vbNullString, 0)
  152.  
  153.    If lRet Then
  154.        sBuffer = StrConv(sBuffer, vbUnicode)
  155.        Unicode2UTF8 = Left$(sBuffer, lRet)
  156.    End If
  157. End Function
  158.  
  159.  


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: Psyke1 en 22 Diciembre 2012, 02:10 am
Bueno, aquí dejo mi forma de hacerlo. :)
Lo he planteado de una manera un poco diferente y es bastante rápido. Aún así, quizás se podría agilizar aún más con algo de magia negra, pero como la cadena de la url va a ser relativamente corta supongo que no habrá una diferencia muy notable. :silbar:
Si veis cosas a añadir o a mejorar decirlo, aunque creo que se adapta a lo que pide LeandroA en el primer post. ;)



Módulo:
Código
  1. Option Explicit
  2. '============================================================================
  3. ' º Module     : mFastUrlEncode.bas
  4. ' º Author     : Psyke1
  5. ' º Mail       : psyke1@elhacker.net
  6. ' º Date       : 22/12/2012
  7. ' º Recommended Websites :
  8. '       http://foro.h-sec.org
  9. '       http://infrangelux.sytes.net
  10. '============================================================================
  11.  
  12. '// msvbvm60.dll
  13. Private Declare Sub PutMem4 Lib "msvbvm60.dll" (ByVal Ptr As Long, ByVal Value As Long)
  14.  
  15. '// oleaut32.dll
  16. Private Declare Function SysAllocStringByteLen Lib "oleaut32.dll" (ByVal Ptr As Long, ByVal Length As Long) As Long
  17.  
  18. '// kernel32.dll
  19. Private Declare Function WideCharToMultiByte Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long
  20. Private Declare Function MultiByteToWideChar Lib "kernel32.dll" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
  21.  
  22. Private Const CP_UTF8                           As Long = &HFDE9&
  23. Private Const STR_VALID_CHARS                   As String = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_.:~%&="
  24.  
  25. Public Static Function URLEncode(ByVal sUrl As String, _
  26.                                 Optional ByVal bSpacePlus As Boolean, _
  27.                                 Optional ByVal bUTF8 As Boolean = True) As String
  28.  
  29. Dim Q                                           As Long
  30. Dim sHex                                        As String
  31. Dim sChr                                        As String * &H1
  32. Dim lRet                                        As Long
  33. Dim lLen                                        As Long
  34. Dim lStart                                      As Long
  35. Dim sBuffer                                     As String
  36.  
  37.    lLen = LenB(sUrl)
  38.    If lLen Then
  39.        lStart = InStrB(&H1, sUrl, "=", vbBinaryCompare) - &H1
  40.  
  41.        If lStart > -&H1 Then
  42.            lRet = lLen - lStart
  43.            URLEncode = RightB$(sUrl, lRet)
  44.  
  45.            If bUTF8 Then
  46.                PutMem4 VarPtr(sBuffer), SysAllocStringByteLen(&H0, (lRet + lRet))
  47.  
  48.                lRet = WideCharToMultiByte(CP_UTF8, &H0, _
  49.                                           StrPtr(URLEncode), (lRet \ &H2), _
  50.                                           StrPtr(sBuffer), lRet, _
  51.                                           vbNullString, &H0)
  52.  
  53.                URLEncode = LeftB$(StrConv(sBuffer, vbUnicode), (lRet + lRet))
  54.            End If
  55.  
  56.            Q = &H3
  57.  
  58.            Do While Q < lLen
  59.                sChr = MidB$(URLEncode, Q, &H2)
  60.  
  61.                If sChr = "%" Then
  62.                    Q = Q + &H6
  63.                ElseIf InStrB(&H1, STR_VALID_CHARS, sChr, vbBinaryCompare) = &H0 Then
  64.                    sHex = Hex$(AscW(sChr))
  65.                    If LenB(sHex) < &H4 Then sHex = "0" & sHex
  66.  
  67.                    URLEncode = Replace$(URLEncode, sChr, ("%" & sHex), , , vbBinaryCompare)
  68.  
  69.                    lLen = LenB(URLEncode)
  70.                    Q = Q + &H6
  71.                Else
  72.                    Q = Q + &H2
  73.                End If
  74.            Loop
  75.  
  76.            If bSpacePlus Then
  77.                URLEncode = Replace$(URLEncode, "%20", "+", , , vbBinaryCompare)
  78.            End If
  79.  
  80.            URLEncode = (LeftB$(sUrl, lStart) & URLEncode)
  81.        Else
  82.            URLEncode = sUrl
  83.        End If
  84.    End If
  85. End Function
  86.  
  87. Public Static Function URLDecode(ByVal sUrl As String, _
  88.                                 Optional ByVal bSpacePlus As Boolean, _
  89.                                 Optional ByVal bUTF8 As Boolean = True) As String
  90.  
  91. Dim sHex                                        As String
  92. Dim lPos                                        As Long
  93. Dim lLen                                        As Long
  94. Dim lStart                                      As Long
  95. Dim sBuffer                                     As String
  96.  
  97.    If LenB(sUrl) Then
  98.        lStart = InStrB(&H1, sUrl, "=", vbBinaryCompare) + &H2
  99.        URLDecode = sUrl
  100.  
  101.        If lStart > &H2 Then
  102.            lPos = InStrB(lStart, URLDecode, "%", vbBinaryCompare)
  103.  
  104.            Do While lPos
  105.                lPos = lPos + &H2
  106.                sHex = MidB$(URLDecode, lPos, &H4)
  107.                If LenB(sHex) = &H0 Then Exit Do
  108.  
  109.                URLDecode = Replace$(URLDecode, ("%" & sHex), ChrW$("&H" & sHex), , , vbBinaryCompare)
  110.                lPos = InStrB(lPos, URLDecode, "%", vbBinaryCompare)
  111.            Loop
  112.  
  113.            If bSpacePlus Then
  114.                URLDecode = Replace$(URLDecode, "+", " ", , , vbBinaryCompare)
  115.            End If
  116.  
  117.            If bUTF8 Then
  118.                lLen = LenB(URLDecode) \ &H2
  119.                PutMem4 VarPtr(sBuffer), SysAllocStringByteLen(&H0, lLen + lLen)
  120.  
  121.                lLen = MultiByteToWideChar(CP_UTF8, &H0, _
  122.                       StrPtr(StrConv(URLDecode, vbFromUnicode)), lLen, _
  123.                       StrPtr(sBuffer), lLen)
  124.  
  125.                URLDecode = LeftB$(sBuffer, (lLen + lLen))
  126.            End If
  127.        End If
  128.    End If
  129. End Function
  130.  



Pruebas:
Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4. Dim vURL                                    As Variant
  5. Dim vArr()                                  As Variant
  6. Dim sEncodedURL                             As String
  7.  
  8.    vArr() = Array("https://www.google.com.ar/search?q=canción del caballo", _
  9.                   "http://www.taringa.net/buscar/?q=día 12/12/12&interval=", _
  10.                   "https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http://mail.live.com/default.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1", _
  11.                   "https://www.google.com.ar/search?q=casa duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr:1,cd_min:5/12/2012,cd_max:18/12/2012&tbm=isch")
  12.  
  13.    Debug.Print
  14.    Debug.Print String$(15, "-"); Time$; String$(227, "-")
  15.  
  16.    For Each vURL In vArr
  17.        Debug.Print String$(250, "=")
  18.        Debug.Print "Original :", vURL
  19.  
  20.        sEncodedURL = URLEncode(vURL)
  21.        Debug.Print "Enc&Dec  :", URLDecode(sEncodedURL)
  22.        Debug.Print "Enc      :", sEncodedURL
  23.  
  24.        sEncodedURL = URLEncode(vURL, True)
  25.        Debug.Print "Enc&Dec+ :", URLDecode(sEncodedURL, True)
  26.        Debug.Print "Enc+     :", sEncodedURL
  27.    Next vURL
  28.  
  29.    Debug.Print String$(250, "=")
  30. End Sub



Resultado:
Código:
---------------01:55:53-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
==========================================================================================================================================================================================================================================================
Original :    https://www.google.com.ar/search?q=canción del caballo
Enc&Dec  :    https://www.google.com.ar/search?q=canción del caballo
Enc      :    https://www.google.com.ar/search?q=canci%C3%B3n%20del%20caballo
Enc&Dec+ :    https://www.google.com.ar/search?q=canción del caballo
Enc+     :    https://www.google.com.ar/search?q=canci%C3%B3n+del+caballo
==========================================================================================================================================================================================================================================================
Original :    http://www.taringa.net/buscar/?q=día 12/12/12&interval=
Enc&Dec  :    http://www.taringa.net/buscar/?q=día 12/12/12&interval=
Enc      :    http://www.taringa.net/buscar/?q=d%C3%ADa%2012%2F12%2F12&interval=
Enc&Dec+ :    http://www.taringa.net/buscar/?q=día 12/12/12&interval=
Enc+     :    http://www.taringa.net/buscar/?q=d%C3%ADa+12%2F12%2F12&interval=
==========================================================================================================================================================================================================================================================
Original :    https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http://mail.live.com/default.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1
Enc&Dec  :    https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http://mail.live.com/default.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1
Enc      :    https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http%3A%2F%2Fmail.live.com%2Fdefault.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1
Enc&Dec+ :    https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http://mail.live.com/default.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1
Enc+     :    https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1312101221&rver=6.1.6206.0&wp=MBI&wreply=http%3A%2F%2Fmail.live.com%2Fdefault.aspx&lc=2058&id=64855&mkt=es-US&cbcxt=mai&snsc=1
==========================================================================================================================================================================================================================================================
Original :    https://www.google.com.ar/search?q=casa duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr:1,cd_min:5/12/2012,cd_max:18/12/2012&tbm=isch
Enc&Dec  :    https://www.google.com.ar/search?q=casa duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr:1,cd_min:5/12/2012,cd_max:18/12/2012&tbm=isch
Enc      :    https://www.google.com.ar/search?q=casa%20duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr%3A1%2Ccd_min%3A5%2F12%2F2012%2Ccd_max%3A18%2F12%2F2012&tbm=isch
Enc&Dec+ :    https://www.google.com.ar/search?q=casa duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr:1,cd_min:5/12/2012,cd_max:18/12/2012&tbm=isch
Enc+     :    https://www.google.com.ar/search?q=casa+duplex&num=10&hl=es&safe=off&biw=1680&bih=925&sa=X&ei=mS7RUIqvHYjW8gSA9oHABg&ved=0CBkQpwUoAw&source=lnt&tbs=cdr%3A1%2Ccd_min%3A5%2F12%2F2012%2Ccd_max%3A18%2F12%2F2012&tbm=isch
==========================================================================================================================================================================================================================================================

DoEvents! :P


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: Danyfirex en 22 Diciembre 2012, 20:20 pm
@Psyke1 tu codigo no simula bien lo de la pagina. hace falta convertirla cadena a UTF8.

debe imprimirlo así:
cobein
Código
  1. https://www.google.com.ar/search?q=canci%C3%B3n
  2.  
el tuyo lo deja así:
Psyke1
Código
  1. https://www.google.com.ar/search?q=canci%F3n

saludos


Título: Re: [Reto] UrlEncode y UrlDecode
Publicado por: Psyke1 en 22 Diciembre 2012, 21:15 pm
Ok, se me escapó. :silbar: Gracias, ya lo he corregido.
Ahora tan sólo queda hacer los test con CTiming. :)

DoEvents! :P