2016-06-09 85 views
2

來自roUrlTransfer對象的AsyncPostFromString方法會生成超時30秒的CURL請求。更改來自roku的CURL請求的默認超時時間

port = CreateObject ("roMessagePort") 
ut = CreateObject ("roUrlTransfer") 
ut.setMessagePort(port) 
ut.AsyncPostFromString(data) 

有誰知道是否有任何方式更改使用的是Roku SDK捲曲超時默認值?

回答

0

無法更改請求的默認超時值。但是,在管理異步請求處理程序中的超時時,您可以手動執行此操作。大多數應用程序應該使用異步請求,所以無論如何你都會進行類似的檢查。另外請務必撥打roUrlTransfer上的asyncCancel()來清理請求。

' given a url that will timeout 
url = "http://www.mocky.io/v2/5a75d6902e000068006ab21a?mocky-delay=1000ms" 

' and a timeout in ms 
timeout = 100 

' create a roUrlTransfer for the request 
urlTransfer = CreateObject("roUrlTransfer") 
urlTransfer.setUrl(url) 
port = CreateObject("roMessagePort") 
urlTransfer.setMessagePort(port) 

' request the URL 
if urlTransfer.asyncGetToString() 
    event = wait(timeout, port) 
    if type(event) = "roUrlEvent" 
     print "urlTransfer success" 

    else if event <> invalid 
     print "event emitted: " + type(event) 

    else 
     print "urlTransfer timed out" 
     urlTransfer.asyncCancel() 

     ' alternatively: measure the request time against timeout using roTimeSpan 
    end if 
end if 

正如代碼所指出的,你會想使用roTimeSpan如果你正在處理您的等待循環其他請求測量超時(在情況下,等待超時是不一樣的請求超時)。