REQUEST A DEMO

Encode URLs with ClearBasic

At Dovetail one of the things we sell is Clarify Helpdesk support. This means that customers having problems with Clarify Client can get support when they run into issues. We had an interesting case recently that I thought would be good to share with the community.

 

Under the hood Clarify Client uses a variant of Visual Basic called ClearBasic which makes the behavior of their windows application customizable via scriptability. Using ClearBasic, Clarify developers can modify the script used behind any of the forms in the Clarify Client application. We have a customer that is integrating one of their Clarify Client forms with another enterprise application using HTTP GET Requests. They ran into a problem with GET requests getting truncated when special characters were present in the request URL. When constructing HTTP GET requests parameters you should UrlEncode the value of each parameter.

ClearBasic UrlEncode

 

We found a Visual Basic example of doing URLEncoding and ported it to ClearBasic. Here it is:

 

 

Sub Usage()
Dim encoded as String
encoded = UrlEncode(“foo#bar”)
Debug.Print encoded ‘should print ‘foo%23bar’
End Sub

 

 

Function UrlEncode(urlText as String) as String
Dim i As Long
Dim ascii As String
Dim encodedText As String
Dim oneChar as String
encodedText = “”

 

For i = 1 to Len(urlText)
oneChar =  Mid(urlText,i,1)
ascii = asc(oneChar)

 

Select Case ascii
Case 48 To 57, 65 To 90, 97 To 122
encodedText = encodedText & chr(ascii)

 

Case 32
encodedText = encodedText & “+”

 

Case Else
If ascii < 16 Then
encodedText = encodedText & “%0” & Hex(ascii)
Else
encodedText = encodedText & “%” & Hex(ascii)
End If

End Select
Next i
UrlEncode = encodedText
End Function