2016-06-09 84 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如果你正在处理您的等待循环其他请求测量超时(在情况下,等待超时是不一样的请求超时)。