Avatar of hrolsons
hrolsons
Flag for United States of America

asked on 

VB6 URLEncode

I'm trying to encode a string to be passed as a URL.  The code I'm currently running is:

Public Function URLEncode( _
    ByVal URL As String, _
    Optional ByVal SpacePlus As Boolean = True) As String
    
    Dim cchEscaped As Long
    Dim HRESULT As Long
    
    If Len(URL) > INTERNET_MAX_URL_LENGTH Then
        Err.Raise &H8004D700, "URLUtility.URLEncode", _
                  "URL parameter too long"
    End If
    
    cchEscaped = Len(URL) * 1.5
    URLEncode = String$(cchEscaped, 0)
    HRESULT = UrlEscape(URL, URLEncode, cchEscaped, URL_ESCAPE_PERCENT)
    If HRESULT = E_POINTER Then
        URLEncode = String$(cchEscaped, 0)
        HRESULT = UrlEscape(URL, URLEncode, cchEscaped, URL_ESCAPE_PERCENT)
    End If

    If HRESULT <> S_OK Then
        Err.Raise Err.LastDllError, "URLUtility.URLEncode", "System error"
    End If
    
    URLEncode = Left$(URLEncode, cchEscaped)
    If SpacePlus Then
        URLEncode = Replace$(URLEncode, "+", "%2B")
        URLEncode = Replace$(URLEncode, " ", "+")
    End If
End Function

Open in new window


Some bad stuff is getting through into the URL and I can't figure out why.
PHPVisual Basic ClassicMySQL Server

Avatar of undefined
Last Comment
gr8gonzo

8/22/2022 - Mon