Forum Discussion

jbrave's avatar
jbrave
Channel Surfer
15 years ago

Need help with cUrl on roku

This works just fine from command line.

curl 'https://api.blah.com/ath/link' \
-d 'client_id=lOnGStringOfCharacters' \
-d 'client_secret=reallyreallylongstringofcharacters' \
-d 'grant_type=password' \
-d 'username=blabla@blababla.com' \
-d 'password=s0mth1ng'
-d 'redirect_uri=http://myblah.com/fail'


Any suggestions on how to convert this into a url to POST and or GET using roURlXfer?

Would the \ be converted to an ampersand? or the -d ? I tried putting it all on one line with ampersands and it was no-go, whereas cUrling it worked perfectly.

- Joel

3 Replies

  • Yes, with an "&". The POST string should look pretty much identical to a querystring, without the leading "?". Note that, typically, it should also be URL encoded like a querystring, as well.

    urlTransfer = CreateObject("roUrlTransfer")
    urlTransfer.SetUrl("https://api.blah.com/ath/link")
    urlTransfer.AddHeader("Content-Type", "application/x-www-form-urlencoded")
    result = urlTransfer.PostFromString("client_id=lOnGStringOfCharacters&client_secret=reallyreallylongstringofcharacters&grant_type=password&username=blabla%40blababla.com&password=s0mth1ng&redirect_uri=http%3a%2f%2fmyblah.com%2ffail")
  • jbrave's avatar
    jbrave
    Channel Surfer
    Hi Endless, thanks.

    One more question: how do I get the response information from this POST? postfromstring just returns an integer, not the response info I get with cUrl on the command line.

    - Joel
  • Use the Async version to get more detailed info returned....

    From the event below you could query for the info you want like GetResponseHeadersArray()

    --Kevin

    Example:

    Function http_post_from_string_with_timeout(val As String, seconds as Integer) as String
    timeout% = 1000 * seconds

    str = ""
    ' m.Http.EnableFreshConnection(true) 'Don't reuse existing connections
    if (m.Http.AsyncPostFromString(val))
    event = wait(timeout%, m.Http.GetPort())
    if type(event) = "roUrlEvent"
    print "1"
    str = event.GetString()
    elseif event = invalid
    print "2"
    Dbg("AsyncPostFromString timeout")
    m.Http.AsyncCancel()
    else
    print "3"
    Dbg("AsyncPostFromString unknown event", event)
    endif
    endif

    return str
    End Function