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: 
mmcbride
Newbie

necessary data rewind wasn't possible

I cannot seem to figure out this problem. I am using AsyncPostFromString to login to a form that only allows posting via username and password. From the traces it appears to work, but I really need the HTML that is returned after a login. GetString always returns the rewind isn't possible error, which I have read on the boards is due to cookies. Since I have the headers for the login I go ahead and construct another http request and just use getString but it always hangs at that point. I'm stumped. If I could get the tcpdump on the roku to collect the full packets it would help, and it would help even more if I understood what the rewind isn't possible message really meant. This code could be totally wrong as I'm still trying to learn. Any help is appreciated.

    http = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
headers = CreateObject("roAssociativeArray")

http.SetPort(port)
http.SetUrl("http://myurl/login")

resp = http.AsyncPostFromString("name=user&password=pass") 'Seems to work but full tcp would help
message = wait(0,http.GetPort())
headers=message.GetResponseHeaders()
for each mes in headers
print mes
next

httptwo = CreateObject("roUrlTransfer")
porttwo = CreateObject("roMessagePort")

httptwo.SetHeaders(headers)
httptwo.SetPort(porttwo)
httptwo.SetUrl("http://myurl/data")

resp=httptwo.GetToString()
messagetwo = wait(0,httptwo.GetPort()) 'Hangs here
print resp
0 Kudos
8 REPLIES 8
RokuChris
Roku Employee
Roku Employee

Re: necessary data rewind wasn't possible

GetToString() is synchronous and doesn't return until the transfer is complete, so there's no need to Wait() for an event after calling it. Your code is hanging because httptwo is not raising any events.
0 Kudos
mmcbride
Newbie

Re: necessary data rewind wasn't possible

Thanks, that was definitely a problem. Now I guess my problem is the post or the headers. The post continues to return the rewind message and the second url redirects back to the login page since it doesn't think it is logged in. Does the AsyncPost syntax look correct for a simple post form? Is there a way to increase the packet capture size of tcpdump on the roku or should I dig and try and find an old hub?
0 Kudos
TheEndless
Channel Surfer

Re: necessary data rewind wasn't possible

Chances are, the login via your first roUrlTransfer object is returning a cookie header for the authenticated session, but you're not sending that back in with your httptwo object, so it's appearing as a completely different, unauthenticated session to the server.
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
RokuKevin
Visitor

Re: necessary data rewind wasn't possible

There is no way to increase the length of a captured packet in the Roku's tcpdump utility.

You would generally send the cookie via the second request via a cookie as theEndless points out.

Here's an example:


request = createObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.setPort(port)

timeout% = 1000 * 5

resArray = CreateObject("roArray", 5, false)
request.setUrl(loginUrl)
if (request.AsyncGetToString())
event = wait(timeout%, request.GetPort())
if type(event) = "roUrlEvent"
resArray.push(event.GetString())
resArray.push(event.GetResponseHeadersArray())
elseif event = invalid
print "AsyncPostFromString timeout"
request.AsyncCancel()
else
print "AsyncPostFromString unknown event"; event
endif
endif

cookiesArray = CreateObject("roArray", 2, True)
for each elem in resArray[1]
for each obj in elem
if obj = "Set-Cookie" Then
cookiesArray.push(elem[obj])
end if
end for
end for

request2 = createObject("roUrlTransfer")
request2.setPort(port)
request2.seturl(userDataUrl)

for each cookie in cookiesArray
request2.AddHeader("Cookie", cookie)
end for

userData = request2.GetToString()




--Kevin
0 Kudos
mmcbride
Newbie

Re: necessary data rewind wasn't possible

So after looking at a lot of traces I think I have figured out what is going on.

1. Post to URL A with login credentials. (It is odd because the url I post to from the form action is the same url as the HTML for the login page)
2. Server responds with a 302 redirect and a set-cookie in the header of response

I need the cookie from the 302 redirect, but when I look at what is returned I just see the cookies and data from the login page itself. Is that possible to get on the roku?

The below works and shows the 302 redirect with the Set-Cookie in the header and then loads the proper data page.
wget --post-data "name=me%40me.com&password=mypassword" http://my.com/login


If I intentionally send the wrong credentials I get the following headers (GetString was at the top and just returned the full html, I cut it out to save space here):

Cache-Control
Cache-Control
Connection
Content-Language
Content-Length
Content-Type
Date
Expires
Pragma
Server
Set-Cookie
JSESSIONID=495C08A304A500954774853F187668A7; Path=/
Set-Cookie
NSC_tvqfsqbtt-bqq2.sfbm.dpn=ffffffffaf16e4f145525d5f4f58455e445a4a4229a0;expires=Sat, 09-Jul-2011 01:41:56 GMT;path=/


But if I send the correct credentials to the login page I get the following headers (notice no Set-Cookies and GetString doesn't have any data):

GetString:
Cache-Control
Cache-Control
Date
Expires
Pragma
Server


Using wget if I send the correct credentials I get the following headers:

HTTP/1.1 302 Moved Temporarily
Date: Sat, 09 Jul 2011 01:09:25 GMT
Server: Apache-Coyote/1.1
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Cache-Control: no-store
Location: http://me.com/login
Content-Language: en-US
Content-Length: 0
Set-Cookie: JSESSIONID=C65945E3DCDC50F8C03F4B8F93232052; Path=/
Set-Cookie: sp_user=0a19790307e34bdfsddfasdfdsfasdfb67f51cfade4df306c8c7ca11a9095de88b3997d76ac5875cbf0a49e68dd7c74bd5fef3208b538df6cc214a95514e89d828e6cf7867f03e1fe32acc00ab481fa643d59541cc209c4a87e661a8be9af2616f6e460757f3172deae7f611a84f3a2bdd15e1bac8fcb0cf27ef; Domain=.me.com; Expires=Fri, 7 Oct 2011 01:09:26 GMT; Path=/;
Set-Cookie: NSC_tvqfsqbtt-bqq2.sfbm.dpn=ffffadffaf16e48045525d5f4f5845fgddfg445a4a4229a0;expires=Sat, 09-Jul-2011 01:24:26 GMT;path=/
Connection: close
Content-Type: text/plain; charset=UTF-8


Once again, any help is appreciated.
0 Kudos
mmcbride
Newbie

Re: necessary data rewind wasn't possible

Okay, once last piece of information. Here are the headers a reported by a good curl session


< HTTP/1.1 302 Moved Temporarily
< Date: Sat, 09 Jul 2011 02:40:48 GMT
< Server: Apache-Coyote/1.1
< Pragma: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Cache-Control: no-cache
< Cache-Control: no-store
< Location: http://me.com/data
< Content-Language: en-US
< Content-Length: 0
< Set-Cookie: JSESSIONID=7388302826082408D7CE2D53B1273C76; Path=/
< Set-Cookie: sp_user=0a19790307e34bd43d8583e0c7db67f51cfade4df306c8casdfdsf9095de88b3997d76ac5875cbf0a49e68dd7c74bd5fef3208b538df6cc214a95514e89d828e6cf7867f03e1fe32acc00ab481fa643d59541cc209c4a87e661a8be9af2616f6e460757f3172deae7f611a84f3a2b3715e1bac8fcb0cf27ef; Domain=.me.com; Expires=Fri, 7 Oct 2011 02:40:49 GMT; Path=/;
< Set-Cookie: NSC_tvqfsqbtt-bqq2.sfbm.dpn=ffffffffaf16e49f45525dddddd58455e445a4a4229a0;expires=Sat, 09-Jul-2011 02:55:49 GMT;path=/
< Connection: close
< Content-Type: text/plain; charset=UTF-8
<


It appears with the roku I can see all the headers until it hits the Location: header. At that point I guess roku goes ahead and does the redirect and the later headers are not able to be read. I need to read those. Is this a bug or is there a way to get it working?

I can confirm with a lan trace that the AsyncPost is actually working and the returning packet has the proper cookies saying I'm logged in. So the question is why can I not see the headers through code?
0 Kudos
mmcbride
Newbie

Re: necessary data rewind wasn't possible

Wireshark image of packet from Roku. (may have to open in a new window to see the full image)
0 Kudos
mmcbride
Newbie

Re: necessary data rewind wasn't possible

I found a temporary work around so I could finish my app, which is now done, but I doubt the content provider will let me publish it with the work around. Any help on how to read the headers that appear below the Location header in the 302 redirect response?
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.