Your Digital Media Has Never Looked So Good

 
matrixebiz
Topic Author
Posts: 247
Joined: Mon Jan 20, 2014 12:47 pm

Check for 404 error

Fri Oct 06, 2017 4:09 pm

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
 
matrixebiz
Topic Author
Posts: 247
Joined: Mon Jan 20, 2014 12:47 pm

Re: Check for 404 error

Mon Oct 09, 2017 3:23 pm

Is this a hard question?  All I need to do is check and see if the url is good (valid) or bad (404) in my RSG VideoScene.brs file.
Can I use some of this Function?
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
 
matrixebiz
Topic Author
Posts: 247
Joined: Mon Jan 20, 2014 12:47 pm

Re: Check for 404 error

Fri Oct 13, 2017 5:40 am

Anyone have the correct simplified code for me?
 
matrixebiz
Topic Author
Posts: 247
Joined: Mon Jan 20, 2014 12:47 pm

Re: Check for 404 error

Mon Oct 16, 2017 7:52 am

Anyone?
 
User avatar
squirreltown
Posts: 732
Joined: Sun Apr 21, 2013 2:20 pm

Re: Check for 404 error

Mon Oct 16, 2017 8:29 am

not tested

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

Kinetics Screensaver (kineticsscreensaver), Kinetics³ Screensaver(kinetics3), Kinetics Painter Screensaver (kineticspainter), Kinetics Splash Screensaver (kineticssplash)
 
matrixebiz
Topic Author
Posts: 247
Joined: Mon Jan 20, 2014 12:47 pm

Re: Check for 404 error

Mon Oct 16, 2017 2:33 pm

Hello, thanks for responding but I get this error;

BRIGHTSCRIPT: ERROR: roUrlTransfer: creating MAIN|TASK-only component failed on RENDER 
'Dot' Operator attempted with invalid BrightScript Component or interface reference. (runtime error &hec) in pkg:/components/VideoScene.brs(36)
036:  UT.SetPort(port)

This is a RSG channel - https://github.com/rokudev/videoplayer-channel
 
User avatar
squirreltown
Posts: 732
Joined: Sun Apr 21, 2013 2:20 pm

Re: Check for 404 error

Mon Oct 16, 2017 2:37 pm

The function works, putting it in the right place is up to you. I don't know RSG but it looks like it's in the wrong thread.
Kinetics Screensaver (kineticsscreensaver), Kinetics³ Screensaver(kinetics3), Kinetics Painter Screensaver (kineticspainter), Kinetics Splash Screensaver (kineticssplash)

Who is online

Users browsing this forum: No registered users and 4 guests