更改来自roku的CURL请求的默认超时时间
问题描述:
来自roUrlTransfer对象的AsyncPostFromString方法会生成超时30秒的CURL请求。更改来自roku的CURL请求的默认超时时间
即
port = CreateObject ("roMessagePort")
ut = CreateObject ("roUrlTransfer")
ut.setMessagePort(port)
ut.AsyncPostFromString(data)
有谁知道是否有任何方式更改使用的是Roku SDK卷曲超时默认值?
答
我不这么认为 - 或者这样的选项会在https://sdkdocs.roku.com/display/sdkdoc/ifUrlTransfer的某个地方被提及 - 就像有一个呼叫来设置最低传输速率一样。
但是请尝试在Roku的dev.forum http://forums.roku.com/viewforum.php?f=34中提问 - 他们可能会添加该功能。
答
无法更改请求的默认超时值。但是,在管理异步请求处理程序中的超时时,您可以手动执行此操作。大多数应用程序应该使用异步请求,所以无论如何你都会进行类似的检查。另外请务必拨打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
如果你正在处理您的等待循环其他请求测量超时(在情况下,等待超时是不一样的请求超时)。