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: 
khat33b
Visitor

Infinite wait on POST request with roUrlTransfer

I am trying to send a POST request to an address with some parameters. The app is waiting on the port and not moving forward at all. What am I doing wrong and how do I fix this?

Sub LoginUser()
obj = {}
obj.username = "scb@test.com"
obj.password = "123456"
loginUrl = "http://www.junctiontv.com/scb@test.com/"
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetUrl(loginUrl)
request.AddHeader("Content-Type", "application/x-www-form-urlencoded")
user = {}
date = CreateObject("roDateTime")
ba = CreateObject("roByteArray")
time = date.asSeconds().ToStr()
ba.FromAsciiString("login|cdigm|"+ obj.username + time)
digest = CreateObject("roEVPDigest")
digest.Setup("md5")
digest.Update(ba)
hash = digest.Final()
param = "custId=cdigm&subId=" + obj.username + "&password=" + obj.password + "&ver=1&time="+ time + "&sig=" + hash
if (request.AsyncPostFromString(param))
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
user = ParseJSON(msg.GetString())
if (user.id = -1)
DisplayLoginErrorMessage()
else
print user
end if
endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
end if
End Sub
0 Kudos
2 REPLIES 2
Komag
Roku Guru

Re: Infinite wait on POST request with roUrlTransfer

Wait 0 means wait forever, so maybe you want to set a timeout time (in milliseconds) in case of failure. Also, I don't think you defined "event" anywhere, perhaps you meant "msg" there.
0 Kudos
RokuMarkn
Visitor

Re: Infinite wait on POST request with roUrlTransfer

You didn't call request.SetMessagePort to associate the message port with the request.

--Mark
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.