如何使API请求在Roku公司的一些服务器 [英] How to make api request to some server in roku

查看:195
本文介绍了如何使API请求在Roku公司的一些服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Roku公司和Roku公司特定语言(BasicScript)的工作非常新。我需要API调用的一些服务器,以获取渠道。我不理解怎么做,在Roku公司。请建议。

解决方案

这里是直接的方式做到这一点,而不必依赖于包含在你的SDK中的code库的语法:

阻塞方法(所有程序执行停止,直到网址检索):

<$p$p><$c$c>url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML" XFER = CREATEOBJECT(roURLTransfer) xfer.seturl(URL) 数据= xfer.gettostring()

非阻塞方法,你可以做其他的事情在等待数据:

<$p$p><$c$c>url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML" XFER = CREATEOBJECT(roURLTransfer) xfer.seturl(URL) 端口= CREATEOBJECT(roMessagePort) xfer.setport(端口) 定时器= CREATEOBJECT(roTimeSpan) timer.mark() xfer.asyncgettostring() 而真正的     味精=等待(100口)100毫秒暂停     如果类型(MSG)=​​roUrlEvent再         如果msg.getresponse code()= 200,然后             数据= msg.getstring()             标题= msg.getresponseheadersarray()             退出而         其他             xfer.asynccancel()         如果结束     其他         打印做一些有用的东西,而我们等待数据     如果结束     如果timer.totalmilliseconds()&GT; 500则         ?超时超标         退出而     如果结束 端,而 打印*************** HEADERS ****************** 在头每个标题 打印头 结束了 打印***************数据*********** 打印数据 打印 ****************************************

I am very much new in working with roku and roku specific language( BasicScript ). I need to make api calls to some server to get the channels. I am not understanding how to do it in roku. Please suggest.

解决方案

here is the direct way to do it without having to rely on the syntax of the code libraries that are included in your SDK:

Blocking Method (all program execution stops until the URL is retrieved):

url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML"
xfer=createobject("roURLTransfer")
xfer.seturl(url)
data=xfer.gettostring()

Non Blocking Method where you can do other things while waiting for data:

url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML"
xfer=createobject("roURLTransfer")
xfer.seturl(url)
port=createobject("roMessagePort")
xfer.setport(port)
timer=createobject("roTimeSpan")
timer.mark()
xfer.asyncgettostring()
while true    
    msg=wait(100,port) '100 millisecond pause
    if type(msg)="roUrlEvent" then

        if msg.getresponsecode()=200 then
            data=msg.getstring()
            headers=msg.getresponseheadersarray()
            exit while
        else
            xfer.asynccancel()
        end if
    else
        print "do something useful while we wait for data"   
    end if
    if timer.totalmilliseconds() > 500 then
        ?"timeout exceeded"
        exit while
    end if
end while
print "***************HEADERS******************"
for each header in headers
print header
end for
print "***************DATA*********************"
print data
print "****************************************"

这篇关于如何使API请求在Roku公司的一些服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆