Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
squirreltown
Roku Guru

RSS parse

I have an rss feed working fine from an http GET request from the Roku. I am trying to change it to http POST. I am getting an error and the feed isnt being parsed. I know the rss feed is outputting the proper format/info from the POST request, but am having trouble capturing it back at the Roku.
Here is the error
<br />
Found error in the file '<b>/home/phcom/public_html/web/rss13/index3.php</b>' at line <b>30</b>.<br />
Called '<b>getAll</b>' function with erroneous argument #<b>0</b>.<br /><br />

and the calling function:
Function  SendFavsViaPost(feed_url)

strx = ReadAsciiFile("tmp:/apfavorites")

m.http.SetUrl(feed_url)
m.http.PostFromString("AID=" + strx)
xml=m.http.GetToString()

print xml

rss=CreateObject("roXMLElement")
if not rss.Parse(xml) then stop
print "rss@version=";rss@version
pl=CreateObject("roList")
for each item in rss.channel.item
pl.Push(newPhotoFromXML(m.http, item))
print "photo title=";pl.Peek().GetTitle()
next
return pl

End Function
Kinetics Screensavers
0 Kudos
13 REPLIES 13
RokuChris
Roku Employee
Roku Employee

Re: RSS parse

That's a PHP error. It's being generated by the server, not by your BrightScript.

And it looks like you're doing a POST followed by a GET, so when you print the response, it's the result of the GET not the POST. You probably want to do one or the other, not both.
0 Kudos
squirreltown
Roku Guru

Re: RSS parse

Thank you Chris, I'm obviously not clear on this.

this is supposed to append to the URL in a POST request right? - m.http.PostFromString("AID=" + strx)

And then this is supposed to capture the body result from the request - xml=m.http.GetToString()

without the second line above, how do i get the result into the xml variable? There is no PostToString() is there?
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: RSS parse

Both PostFromString and PostFromFile discard the response. If you want the response from a POST you should use AsyncPostFromX. The body is available from the roUrlEvent (GetString).

--Mark
0 Kudos
squirreltown
Roku Guru

Re: RSS parse

Thank you Mark, I read that but it seemed like the GetToString() approach might work since the docs don't actually say it only works on GET requests but it should have been obvious. Could you help me out on how to write that line since there are no examples in the docs and don't know how to get a URL event - Does it have to be in a loop like some other events?

m.http.AsyncPostFromString("AID=" + strx)
xml=m.http.GetString()


this of course doesnt work.
Kinetics Screensavers
0 Kudos
squirreltown
Roku Guru

Re: RSS parse

Ok tried this but the result is not getting into the variable.

Function  SendFavsViaPost(feed_url)

strx = ReadAsciiFile("tmp:/apfavorites")
m.http.SetUrl(feed_url)
m.http.AsyncPostFromString("AID=" + strx)

while true
msg = Wait( 100, m.port )
If msg = invalid Then
' Timeout
Return "Error: timed out"
Else If Type( msg ) = "roUrlEvent" Then
Return msg.GetString()
xml = msg.GetString()
exit while

End If
end while


rss=CreateObject("roXMLElement")
if not rss.Parse(xml) then stop
print "rss@version=";rss@version
pl=CreateObject("roList")
for each item in rss.channel.item
pl.Push(newPhotoFromXML(m.http, item))
print "photo title=";pl.Peek().GetTitle()
next
return pl

End Function
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: RSS parse

Do you really want to return from SendFavsViaPost as soon as you get the roUrlEvent? None of the code after the while loop will be executed.

--Mark
0 Kudos
TheEndless
Channel Surfer

Re: RSS parse

"RokuMarkn" wrote:
Do you really want to return from SendFavsViaPost as soon as you get the roUrlEvent? None of the code after the while loop will be executed.

--Mark

He's also only waiting 100 milliseconds for a response from the server, which seems awfully short, so I'd bet he's hitting the "msg = invalid" condition first.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
squirreltown
Roku Guru

Re: RSS parse

I'm getting msg=invalid with it set to 8000 which is about 4 times longer than it ever takes. This response works fine with a GET request, and I know the POST is getting through because its writing an xml file to the server at the same time so i can check. I'm out of ideas.
Kinetics Screensavers
0 Kudos
RokuMarkn
Visitor

Re: RSS parse

Did you set m.port as the message port for m.http?

--Mark
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.