How to make api request to some server in roku(如何向 roku 中的某些服务器发出 api 请求)
问题描述
我在使用 roku 和 roku 特定语言 (BasicScript) 方面非常陌生.我需要对某些服务器进行 api 调用以获取频道.我不明白如何在 roku 中做到这一点.请提出建议.
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.
推荐答案
这是直接的方法,无需依赖 SDK 中包含的代码库的语法:
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:
阻塞方法(所有程序执行停止,直到检索到 URL):
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 "****************************************"
这篇关于如何向 roku 中的某些服务器发出 api 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何向 roku 中的某些服务器发出 api 请求


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01