本文介紹了如何向 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 請求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!