jbrave
15 years agoChannel Surfer
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:
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