Jump to content

Recommended Posts

Posted (edited)

URLdecode does not work well:

#include <WinHttp.au3>
#include <WinHttpConstants.au3>

local $text = "rápido"
MsgBox(0,'', URLDecode(__WinHttpURLEncode($text)) )


; __WinHttpURLEncode translates "á" correctly with %C3%A1, but URLdecode (I found it in the forum) does not reverse it right.

Func URLDecode($urlText)
    $urlText = StringReplace($urlText, "+", " ")
    Local $matches = StringRegExp($urlText, "\%([abcdefABCDEF0-9]{2})", 3)
    If Not @error Then
        For $match In $matches
            $urlText = StringReplace($urlText, "%" & $match, BinaryToString('0x' & $match))
        Next
    EndIf
    Return $urlText
EndFunc   ;==>URLDecode

 

Any idea how to solve?

Edited by frank10
Posted

Try this (partly tested)

#include <Constants.au3>
#include <WinHttp.au3>
#include <WinHttpConstants.au3>

Local $text = "rápidéo èthïmê"
Local $sEncode = __WinHttpURLEncode($text)
MsgBox(0, '', $sEncode)
MsgBox (0,"",URLDecode($sEncode))

Func URLDecode($urlText)
  Local $sDecoded
  $urlText = StringReplace($urlText, "+", " ")
  Local $matches = StringRegExp($urlText, "\%([a-fA-F0-9]{2})", 3)
  If Not @error Then
    For $i = 0 To UBound($matches) - 1
      $matches[$i] = Dec($matches[$i])
    Next
    $sDecoded = StringFromASCIIArray($matches, 0, -1, 2)
    $urlText = StringRegExpReplace($urlText, "\%([a-fA-F0-9]{2})\%([a-fA-F0-9]{2})", "%%")
    For $i = 1 To StringLen($sDecoded)
      $urlText = StringReplace($urlText, "%%", StringMid($sDecoded, $i, 1), 1, 1)
    Next
  EndIf
  Return $urlText
EndFunc   ;==>URLDecode

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...