Roku:使用roUrlTransfer对POST请求进行无限等待

时间:2015-07-23 09:45:51

标签: roku brightscript

我正在尝试向一个带有一些参数的地址发送POST请求。该应用程序正在等待端口,而不是向前移动。我做错了什么,如何解决这个问题?

Sub LoginUser()
    obj = {}
    obj.username = "scb@test.com"
    obj.password = "123456"    
    loginUrl = "http://www.test.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|test|"+ obj.username + time)
    digest = CreateObject("roEVPDigest")
    digest.Setup("md5")
    digest.Update(ba)
    hash = digest.Final()
    param = "custId=test&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

1 个答案:

答案 0 :(得分:0)

您已在http://forums.roku.com/viewtopic.php?f=34&t=87939#p495981得到回复,必须在port请求中注册roUrlTransfer,以便事件进入该端口。