Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Level 7

Can the http post methods return xml data?

Hi all, new here on this board. I am trying to develop an REST application using post methods. I need to be able to send xml data and receive xml data from my server. Is this possible?
0 Kudos
1 Reply
Highlighted
Level 9

Re: Can the http post methods return xml data?

You must use the async versions of the http post methods in order to get the return xml data. The synchronous POST calls do not return the xml data. The return data can be read from the roUrlEvent returned.

Example:

Function post_req_resp(url As String) as dynamic
obj = CreateObject("roUrlTransfer")
obj.SetPort(CreateObject("roMessagePort"))
obj.SetUrl(url)

timeout% = 1500
num_retries% = 5
str = ""
while num_retries% > 0
if (obj.AsyncPostFromString(""))
event = wait(timeout%, obj.GetPort())
if type(event) = "roUrlEvent"
respCode = event.GetResponseCode()
if respCode = 200 then
return event.GetString()
else
return invalid
end if
elseif event = invalid
obj.AsyncCancel()
' Reset connection on timeout
obj = CreateObject("roUrlTransfer")
obj.SetPort(CreateObject("roMessagePort"))
obj.SetUrl(url)
timeout% = 2 * timeout%
else
print "roUrlTransfer::AsyncGetToString(): unknown event"
endif
endif
num_retries% = num_retries% - 1
end while
return invalid
End Function


--Kevin
0 Kudos