Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jbrave
Level 8

cUrl and AsyncPostFromString

I'm having trouble setting up an roURLTransfer and getting back the headers. I'm not sure what I'm doing wrong, I'm mostly using code that I used sucessfully before for this.

I'm trying to pass a username and password over https to a server and extract a returned code from the header.

Here is the cUrl command line that works:

curl -k -u usernameSmiley Tongueassword --trace-ascii test.txt --request POST -d "t" https://website.com/user.xml

The code I am looking for is in the trace file, test.txt.

On the Roku I'm just not getting jack back from my asyncPostFromString("t") but an empty roAssociativeArray if I use: msg.GetResponseHeadersArray()
and an empty roArray if I use: msg.GetResponseHeaders().

If I use AsynchGetToString instead I get a pile of headers back, just not the right ones - I think it is following a redirect on that page which is intended for browsers, but curl doesn't seem to follow, but the Roku appears to.

Here's the code:


function GetHeaders(username as string, password as string) as object
xfer = CreateObject("roUrlTransfer")
xfer.EnableFreshConnection(true)
xfer.SetCertificatesFile("common:/certs/ca-bundle.crt")
xfer.seturl("https://website.com/user.xml")
xfer.SetUserAndPassword(username,password)

xport=CreateObject("RoMessagePort")
xfer.setport(xport)
if (xfer.asyncPostFromSTring("t"))
?"xfer.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()
event={result:hedone, headers:hedtwo}
end if
end if
return event
End Function
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
7 Replies
TomCorwine
Level 7

Re: cUrl and AsyncPostFromString

Have you tried running a packet sniffer to see what's going on? That way you can see the difference between the CURL request and roUrlTransfer.
0 Kudos
evilmax17
Level 7

Re: cUrl and AsyncPostFromString

What does head.GetResponseCode() give you?
My Roku Channels:
Viddler - viddler.com
Tested Fan - tested.com | Jamie & Adam
This is my next - theverge.com
1080p Showcase - RIP
Whiskey Media - RIP
======================
http://www.binarymoustache.com
0 Kudos
TheEndless
Level 9

Re: cUrl and AsyncPostFromString

Two things.. 1) as evilmax17 asked, what's the response code? With roUrlTransfer, you only get headers for 200s. 2) Are you sure the site doesn't require Basic authentication? SetUserAndPassword only works with NTLM/Digest. If you need Basic, then you should be explicitly setting the Authorization header.
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
jbrave
Level 8

Re: cUrl and AsyncPostFromString

Ok, I changed the code as suggested:

Two things.. 1) as evilmax17 asked, what's the response code? With roUrlTransfer, you only get headers for 200s. 2) Are you sure the site doesn't require Basic authentication? SetUserAndPassword only works with NTLM/Digest. If you need Basic, then you should be explicitly setting the Authorization header.


AsyncPostFromString started returning headers, just not the ones I wanted and a 302 response code.

I changed the method to AsyncHead and strangely, using msg.GetResponseHeadersArray() I get the headers I want, but not with msg.GetResponseHeaders()!

That solves my problem, but it would still be nice to understand what is going on with this site a little better. If only I could see the url the way it looks when the server gets it.

I enabled tcpdump on the roku, but it doesn't seem to show https traffic in the log. Understandable, it is supposed to be secure.

Thanks for the help!

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
RokuKevin
Level 9

Re: cUrl and AsyncPostFromString

Object GetResponseHeadersArray(String feature) returns all the headers if multiple headers have the same name.

There is a bug/feature where GetResponseHeaders() only returns the headers for 200s status codes and GetResponseHeadersArray() returns headers for all status codes.

tcpdump should get the first 256 bytes of all packets including https packets (of course the data will be encrypted and therefore unreadable).

--Kevin
0 Kudos
jbrave
Level 8

Re: cUrl and AsyncPostFromString

"RokuKevin" wrote:
Object GetResponseHeadersArray(String feature) returns all the headers if multiple headers have the same


Hi Kevin,

The bug I'm talking about here is that if you put any string in GetResponseHeadersArray("string") the action will fail.

Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
RokuKevin
Level 9

Re: cUrl and AsyncPostFromString

That's a documentation bug. GetResponseHeaderArray() takes no arguments.

--Kevin
0 Kudos