Forum Discussion

jbrave's avatar
jbrave
Channel Surfer
15 years ago

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 username:password --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

7 Replies

  • 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.
  • 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.
  • jbrave's avatar
    jbrave
    Channel Surfer
    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
  • 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
  • jbrave's avatar
    jbrave
    Channel Surfer
    "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
  • That's a documentation bug. GetResponseHeaderArray() takes no arguments.

    --Kevin