如何向roku中的某个服务器发送api请求
问题描述:
我在roku和roku特定语言(BasicScript)中使用非常新。我需要对某些服务器进行api调用以获取频道。我不理解如何在roku中做到这一点。请建议。如何向roku中的某个服务器发送api请求
答
这里是为了做到这一点,而不必依赖于包含在你的SDK代码库的语法直接的方式:
阻塞方法(所有程序执行停止,直到URL被检索) :在等待数据
url="http://myserver.com/anExampleQuery?getmydata&apikey=AX5GZP5LL45D987D0&format=XML"
xfer=createobject("roURLTransfer")
xfer.seturl(url)
data=xfer.gettostring()
非阻塞的方法,你可以做其他事情:
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 "****************************************"
答
http=NewHttp("http://server address")
rsp = http.GetToStringWithRetry()
print rsp 'To check the response text from server
+0
这仅适用于包含SDK中的URL实用程序文件之一的文件,例如TwitterOauth示例中的url.brs。 url.brs是一个包含roURLTransfer对象的brightscript函数库,它在执行时间方面增加了一点点开销。 – alphablender 2012-11-30 00:04:44
我收到以下错误BRIGHTSCRIPT:错误:roUrlTransfer:class线程上的PLUGIN | MARKUP RENDER: – rkaartikeyan 2017-02-26 21:40:18