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

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.

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?

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

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.

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

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

“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.

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.

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

–Mark

yea I actually got that part right this time. This same function works fine if I change the POST stuff to GET, which is the way it is normally.

Ive just changed

m.http.SetUrl(feed_url)

to

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

and

xml=m.http.GetToString()

to

while true
    msg = Wait(8000, m.port )
    If msg = invalid Then
    print "Error: invalid"
    Else If Type( msg ) = "roUrlEvent" Then
    if msg.GetString()
    xml= msg.GetString()
    End If
    end if

...............

it prints the error and crashes on the next block because the xml variable is empty

“squirreltown” wrote:
yea I actually got that part right this time. This same function works fine if I change the POST stuff to GET, which is the way it is normally.

Ive just changed

m.http.SetUrl(feed_url)

to

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

and

xml=m.http.GetToString()

to

while true
    msg = Wait(8000, m.port )
    If msg = invalid Then
    print "Error: invalid"
    Else If Type( msg ) = "roUrlEvent" Then
    if msg.GetString()
    xml= msg.GetString()
    End If
    end if

...............

it prints the error and crashes on the next block because the xml variable is empty
That’s actually a much bigger change that it may look. You went from the synchronous GetToString() to the asynchronous AsycnPostFromString() method. The former doesn’t require a port and wait loop, while the second does, so I’d bet it is an issue with the port you’re listening on. Try just swapping:

xml = m.http.GetToString()

with:

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

and see if it works. That’s swapping synchronous for synchronous…

Thank you TheEndless & Mark- So it turns out to be a port issue after all. I thought the port was being set in the function that created it but i guess not. I added a setmessageport line and that led to it getting fixed, it runs fine now.

hello
i want to send username and password in post form
i not found any right way to do it kindly help me.
i have username in one variable and password in other variable
and i have url so how i send request to the server in post form