Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
irimiNage
Visitor

Help getting cookies using ifHttpAgent?

Hi,

I'm new to BrightScript but trying to put together a proof of concept for Roku as a streaming client for IP VOD from my employer, a paytv broadcaster. I'm trying to grab a session id from a cookie on our website so I can pass it back as part of a JSON login data structure but I'm really struggling to get more than the header and body back from the server. This is my best attempt so far: I can only make the GetCookies call at the expense of not getting the header and body, and I still don't get any cookies :(. Any help appreciated ....

url = "http://www.geekzone.co.nz"
request = CreateObject("roUrlTransfer")
request.SetUrl( url )
request.EnableCookies()
request.EnableFreshConnection(true)

xport=CreateObject("RoMessagePort")
request.setport(xport)
if (request.asyncPostFromSTring("t"))
'"request.async is true"
msg = wait(0,xport)
'"we should have a message"
if type(msg) = "roUrlEvent"
'"ok we have a url event"
hedone={}
hedtwo={}
hedone=msg.GetResponseHeadersArray()
hedtwo=msg.GetResponseHeaders()
body=msg.GetString()
code=msg.GetResponseCode()
event={result:hedone, headers:hedtwo, body:body, code:code}
end if
end if

'html = request.GetToString()
'print html
'print "len body = ", len(body)

print "getting geekzone cookies"
cookies = request.GetCookies( ".geekzone.co.nz", "/" )
print "printing geekzone cookies"
for each cookie in cookies
print cookie
end for
0 Kudos
3 REPLIES 3
TheEndless
Channel Surfer

Re: Help getting cookies using ifHttpAgent?

What the.. what? When did they add cookie support to ifHttpAgent? :shock:

Edit: I've never used it (obviously), so I can't answer directly how to use GetCookies, but you could just pull the cookie directly from the headers you retrieved when you got the content.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
irimiNage
Visitor

Re: Help getting cookies using ifHttpAgent?

Thanks for the quick response. I initially tried some cut'n'paste hackery around parsing headers for cookies before I found the GetCookies call. For some reason (maybe redirects, not sure) I couldn't see the Set-Cookie in the headers returned. I've got a little python script that shows geekzone returns a cookie on their main page so I'll go back to that & see if I can parse a cookie out of the header on the Roku. Cheers
0 Kudos
bosborne
Visitor

Re: Help getting cookies using ifHttpAgent?

Did you ever figure out how to get Cookies to print out?
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.