3

I need to URL encode a variable that is being passed into a web service.

testcategory = "Action and Adventure"
jsonRequest = CreateObject("roUrlTransfer")
jsonRequest.SetURL("http://myurl.com/?method=getRokuCategorizedSeriesListing&category=" + testcategory)

I need to have whatever the value be for "testcategory" to be url encoded to be passed it to this web service call. In this example I would need "Action and Adventure" to be "Action%20and%20Adventure"

Is there a Brightscript function to accomplish this?

Any help would be very appreciated.

Thank you!

Josh Scott
  • 3,790
  • 7
  • 29
  • 31

1 Answers1

3

Place this function in one of your brightscript file

Function HttpEncode(str As String) As String
    o = CreateObject("roUrlTransfer")
    return o.Escape(str)
End Function

and then you can use the function HttpEncode as

jsonRequest.SetURL("http://myurl.com/?method=getRokuCategorizedSeriesListing&category=" + HttpEncode(testcategory) )
  • 1
    Escape was the right answer. Although I realized I already had a roUrlTransfer object instantiated so I just used that. – Josh Scott Jun 19 '14 at 14:06