matrixebiz
8 years agoRoku Guru
Check for 404 error
Hello, is there a simple Brightscript 2-3 lines of code that I can use to check if a url is alive or not and if it gives a 404 error then return the 404 error so I can try another url? Thank you
Function check(thisurl) as string
request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
request.SetUrl(thisurl)
if (request.AsyncGetToString())
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
print"good"
return "good"
elseif (code =400 or code=404)
print("image not found")
return "bad"
else
print"error"; code
return "generic bad code"
endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid
End Function
Function Ping()
UT = CreateObject( "roUrlTransfer" )
port = CreateObject("roMessagePort")
UT.SetPort(port)
UT.SetUrl("URL HERE")
UT.AsyncHead()
event = wait (0, port)
if type(event) = "roUrlEvent"
if event.GetResponseCode() = 200
'do something'
else if event.GetResponseCode() = 404
'do something else'
end if
end if
End Function